Linux 不记录创建时间,文件只有 3 个时间记录:上次访问、上次修改内容和上次修改 inode。所以你有3个选择:
要删除 2018 年 4 月 29 日下午 4:00 之前修改的所有文件:
find . -type f ! -newermt '04/29/2018 16:00:00' -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
要删除 2018 年 4 月 29 日下午 4:00 之前访问的所有文件:
find . -type f ! -newerat '04/29/2018 16:00:00' -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
要删除在 2018 年 4 月 29 日下午 4:00 之前更改权限的所有文件:
find . -type f ! -newerct '04/29/2018 16:00:00' -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
您可能不想将上述命令作为 运行root
,并记住备份任何重要文件。
您应该谨慎对待日期值。尽管上个月我对硬盘进行了完整的格式化,但我的主目录中有一些文件可以追溯到 2014 年!