我有一个文件夹里有很多文件。我需要删除所有在7月1日之前创建的文件。如何在Bash脚本中做到这一点?
touch -t 201007010000 dummyfile
find /path/to/files -type f ! -newer dummyfile -delete
find /file/path ! -newermt "Jul 01"
find /file/path ! -newermt "Jul 01" -type f -print0 | xargs -0 rm
find
有这个选项。然而,Unix/Linux 没有创建日期的概念,所以我会使用 -newermt
。c
是指 inode 的状态更改,而不是“创建”。 - Dennis Williamson
find /path/to/files -type f -newer dummyfile
中没有“!”符号,但是-delete
无法正常工作。将输出传递到带有rm
的for
循环中可以解决问题,但是有更简单的方法,对吗? - Tom Kellyfind
命令缺少-delete
选项,可以尝试使用-exec rm {} +
,如果你的find
命令也不支持使用+
的-exec
选项,则可以尝试使用\;
替代。 - tripleee