Val*_*ami 41
使用find
仍然是删除文件的首选方式。有关更多信息,请参阅http://mywiki.wooledge.org/UsingFind。
一种方法是创建一个带有时间戳的文件。例如
touch -t 201311220000 /tmp/timestamp
Run Code Online (Sandbox Code Playgroud)
现在删除与find
时间戳匹配的文件 GNU (假设在当前目录中),例如:
find . -type f ! -newer /tmp/timestamp -delete
Run Code Online (Sandbox Code Playgroud)
或非 GNU 查找
find . -type f ! -newer /tmp/timestamp -exec rm {} \;
Run Code Online (Sandbox Code Playgroud)
Sté*_*las 35
使用 GNU 或某些 BSD find
:
find . ! -newermt 2013-11-22 ! -type d -delete
Run Code Online (Sandbox Code Playgroud)
请注意,它会检查文件的最后修改时间。在某些 BSD 上,您可以使用-newerBt
代替-newermt
来检查文件的 inode出生时间(如果可用)。