我有一个简单的bash脚本,cron将在每晚午夜运行,它会创建一个备份或文件,并将它们存储为我的Dropbox中的.tar.gz。然而,在此之前,我需要脚本删除前一晚的备份。
要执行此操作,我目前正在运行此命令:
find ~/Dropbox/Backups/casper/* -mtime +0.5 -exec rm {} \;
我认为应该删除超过半天的任何内容 - 但它似乎不起作用(它会保留之前的夜晚备份,但在此之前删除任何内容)
有人能指出我正确的方向吗?谢谢
答案 0 :(得分:1)
来自find
的联机帮助页:
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the
interpretation of file modification times.
-atime n
File was last accessed n*24 hours ago. 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.
由此我们可以看到0.5被删除,然后需要1天前。您可能希望改为使用-mmin
。
例如(来自babah):
# 720 is 60 times 12
find ~/Dropbox/Backups/casper/* -mmin 720 -print -exec rm {} \;