【发布时间】:2019-05-17 10:21:44
【问题描述】:
我正在尝试使用 find 命令删除早于 1 天(创建日期)的备份文件夹,但它不起作用
文件夹 ls -l:
drwxrws---+ 2 root data 42 Mai 15 16:46 15-05-2019
drwxrws---+ 2 root data 89 Mai 16 14:19 16-05-2019
创建日期为 5 月 15 日。
这个 cmd 应该可以工作:
find /data/backup/VMs/centos/ -type d -mtime +1 -exec rm {} \;
我先尝试了这个,看看在删除之前会发生什么:
find /data/backup/VMs/centos/ -type d -mtime +1 -exec ls {} \; >> find_test.txt
应该把要删除的文件夹写入文件,但是txt文件是空的。
除了使用查找之外,如何使用名称中的日期删除此文件夹?
【问题讨论】:
-
UNIX 不存储文件的创建日期,但看起来您的意思是修改日期。您没有在问题中显示运行命令时的日期/时间是什么 - 您是否从手册页
When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.中考虑到(同样适用于 mtime)? -
感谢您的帮助,如果我打开文件夹,日期会更改吗?
-
“文件夹”我相信是一个 Windows 术语,在 UNIX 中有目录和文件。当您打开(访问)某些内容时,您会更改它的访问时间,当您修改它时,您会更改它的修改时间 - 两者都可以通过
stat、find等提供。
标签: bash