【发布时间】:2016-12-09 13:06:21
【问题描述】:
所以我正在编写一个 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 天的任何文件?
【问题讨论】:
-
这可能与四舍五入有关。顺便说一句,为什么要
bash?据我所知,find不是内置的。 -
@mustaccio:我怀疑你是对的。不知道您所说的 find 不是“内置”是什么意思。这是一个 linux 系统,所以 bash/find 总是可用的。
-
@MikePurcell,“内置”的意思是“外壳的一部分”,而不是外部工具。如果它不是 shell 的一部分,那么您需要指定您的确切操作系统,以及您的操作系统提供的工具版本。
-
@MikePurcell, ...BSD
find与 GNU 非常不同find与busyboxfind非常不同,尽管这三个都可以从 bash(或 没有 bash,或任何其他shell)。 -
如果是 CentOS,指定它是 CentOS!否则我们不知道该回答什么。 Linux 并不是每个人都默认回答问题的唯一真正的操作系统。 (可以说,一个真正的标准是 POSIX,因为其他一切都试图成为一个超集)。
标签: linux unix centos find-util