查找 - mtime 与 mmin - 奇怪的结果

find - mtime vs mmin - Weird results

所以我正在编写一个 bash 脚本来清除临时文件并 运行 进入莫名其妙的行为。

# Find using mmin flag
find /usr/local/store/file/temp/3_day/ -mmin +$((60*24*3)) -type f > /tmp/old_files_by_mmin.txt

# Find using mtime flag
find /usr/local/store/file/temp/3_day/ -mtime +3 -type f > /tmp/old_files_by_mtime.txt

diff -u /tmp/old_files_by_mmin.txt /tmp/old_files_by_mtime.txt

前几行:

--- /tmp/old_files_by_mmin.txt  2016-08-03 16:56:42.535458820 +0000
+++ /tmp/old_files_by_mtime.txt 2016-08-03 16:56:58.310681524 +0000
@@ -117,59 +117,6 @@
/usr/local/store/file/temp/3_day/image/resize/2016/07/29/11/15/36/1296924350
/usr/local/store/file/temp/3_day/image/resize/2016/07/29/11/47/52/1950191632
/usr/local/store/file/temp/3_day/image/resize/2016/07/29/11/30/01/711250694
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/10/04/15/44313759
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/10/04/15/1589177813
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/10/04/15/1189074525
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/10/56/44/91382315
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/09/43/45/1622776054
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/01/44/57/1465920226
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/01/23/17/1467026748
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/01/15/58/1990201487
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/01/13/19/1990298215
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/01/35/59/518813467
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/12/10/53/1962045410
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/12/31/27/290517373
-/usr/local/store/file/temp/3_day/image/resize/2016/07/31/12/05/08/547481306

为什么 -mmin 标志选择了 mtime 标志没有选择的文件?如果两者都应该找到早于现在 + 3 天的任何文件?

考虑到实现之间的区别,what the POSIX standard for find 指令值得一看:

-mtime n

The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.


同样,根据手册(对于 BSD 查找):

-mtime n[smhdw]

If no units are specified, this primary evaluates to true if the difference between the file last modification time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods.

...因此:在 BSD find 中,默认行为是舍入到完整的 24 小时周期。


对于 GNU find,有一定程度的可配置性;见 -daystart:

-daystart

Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago. This option only affects tests which appear later on the command line.

但是,默认行为在 -atime 的定义中给出:

-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.