我知道unix的find命令有这个选项:
find -version
GNU find version 4.1
-newer file Compares the modification date of the found file with that of
the file given. This matches if someone has modified the found
file more recently than file.
Run Code Online (Sandbox Code Playgroud)
是否有一个选项可以让我找到比某个文件更旧的文件.我想删除目录中的所有文件进行清理.因此,我会发现所有文件都超过N天的替代方案也可以完成这项工作.
qbe*_*220 35
您可以使用a !来否定-newer操作,如下所示:
find . \! -newer filename
Run Code Online (Sandbox Code Playgroud)
如果您想查找上次修改的文件超过7天前使用:
find . -mtime +7
Run Code Online (Sandbox Code Playgroud)
更新:
要避免匹配您要比较的文件,请使用以下内容:
find . \! -newer filename \! -samefile filename
Run Code Online (Sandbox Code Playgroud)
你可以使用否定:
find ... \! -newer <reference>
Run Code Online (Sandbox Code Playgroud)
您也可以尝试使用-mtime/ -atime/ -ctime/ -Btime系列选项.我不会立即记住它们是如何工作的,但它们在这种情况下可能会有用.
小心从find操作中删除文件,尤其是以root身份运行的文件; 有很多方法,同一系统上的非特权恶意进程可以欺骗它删除你不想删除的东西.我强烈建议您阅读GNU查找手册的整个" 删除文件 "部分.