考虑如下,目录路径,
./file1
./dirA
./dirA/dirC
./dirA/dirC/file4
./dirA/dirC/file5
./dirA/dirC/dirD
./dirA/dirC/dirD/file8
./dirA/dirC/dirD/file6
./dirA/dirC/dirD/file7
./dirA/dirE
./dirA/dirE/file9
./dirA/file2
./dirA/file3
./dirB
./dirB/file10
./dirB/dirF
./dirB/dirF/file11
./dirB/dirF/file12
./dirB/dirF/dirG
./dirB/dirF/dirG/file13
最近一个月访问过的文件只有file10和file6。
因此,新的结构将是:
./file1
./dirA
./dirA/dirC
./dirA/dirC/file4
./dirA/dirC/file5
./dirA/dirC/dirD
./dirA/dirC/dirD/file8
./dirA/dirC/dirD/file6
./dirA/dirC/dirD/file7
./dirA/dirE.tgz
./dirA/file2
./dirA/file3
./dirB
./dirB/file10
./dirB/dirF.tgz
我确实尝试了下面的脚本,它的工作,我只是想看看是否可以有一个简单的和更好的方法来做到这一点。
for dir in `find . -type f -atime +30 -printf '%hn' | sort | uniq`; do test `find $dir -type f -atime -30 -print -quit` || tar -czvf $dir.tgz --remove-files $dir; done
提前感谢。
运行这个应该可以完成任务:
find . -type f -atime +30 -exec tar -czvf files.tgz {} +;