find - mtime vs mmin - 奇怪的结果

时间:2016-08-03 17:13:35

标签: linux unix centos find-util

所以我正在使用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天?

1 个答案:

答案 0 :(得分:1)

鉴于实现之间的区别,值得查看what the POSIX standard for find任务:

  

-mtime n

     

如果从初始化时间中减去的文件修改时间除以86400(,其中任何余数被丢弃),则主要应评估为真,为n。

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

  

-mtime n[smhdw]

     

如果未指定单位,如果文件上次修改时间与时间查找之间的差异已开始,向上舍入到下一个完整的24小时时段,则此主要评估为true n 24小时制。

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

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

  

-daystart

     

从今天开始而不是从24小时前测量时间(-amin,-atime,-cmin,-ctime,-mmin和-mtime)。此选项仅影响稍后在命令行中显示的测试。

但是,默认行为与-atime

的定义中给出的相同
  

-atime n

     

上次访问文件n * 24小时前。当find计算出上次访问文件的24小时前的时间段时,将忽略任何小数部分,因此要匹配-atime +1,必须至少在两天前访问过该文件。< / p>