1

我有一个简单的 bash 脚本,每天晚上在午夜运行,它会创建一个备份或文件,并将它们作为 .tar.gz 存储在我的 Dropbox 中。然而,在这发生之前,我需要脚本来删除前一天晚上的备份。

为此,我目前正在运行以下命令:

find ~/Dropbox/Backups/casper/* -mtime +0.5 -exec rm {} \;

在我看来,应该删除半天以上的任何内容 - 但它似乎不起作用(它保留前几个晚上的备份,但在此之前删除任何内容)

有人可以指出我正确的方向吗?谢谢

4

1 回答 1

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 day ago 是必需的。您可能想-mmin改用。

例如(来自 babah):

# 720 is 60 times 12
find ~/Dropbox/Backups/casper/* -mmin 720 -print -exec rm {} \;
于 2012-11-12T10:52:45.873 回答