Closed. This question needs to be more focused. It is not currently accepting answers. Learn more。
想改进这个问题吗?更新问题,使其只关注一个问题editing this post。
两年前关闭。
我有一个目录有100个子目录,每个子目录有100个文件。每天每个子目录中的文件数增加一个。我想在Linux中编写一个脚本,将所有100个子目录复制到另一个位置,每个子目录只有一个最新的文件。怎么做?
如果out目录不在当前目录中:
想改进这个问题吗?更新问题,使其只关注一个问题editing this post。
两年前关闭。
我有一个目录有100个子目录,每个子目录有100个文件。每天每个子目录中的文件数增加一个。我想在Linux中编写一个脚本,将所有100个子目录复制到另一个位置,每个子目录只有一个最新的文件。怎么做?
最佳答案
可以将if块修改为:
if [ $f != "./directory_to_cop" ]
then
mkdir ./directory_to_copy/$f 2>/dev/null
cp $f/`ls -t $f | head -1` ./directory_to_copy/$f
fi
如果out目录不在当前目录中:
mkdir path_to_directory/name_of_directory/$f 2>/dev/null
cp $f/`ls -t | head -1` path_to_directory/name_of_directory/$f
关于linux - 将所有子目录中最新的修改文件复制到具有相同子目录结构的新目录中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46292847/