![我需要解释使用 -newermt 和 -exec ls {} 时 bash find 的行为](https://linux22.com/image/752995/%E6%88%91%E9%9C%80%E8%A6%81%E8%A7%A3%E9%87%8A%E4%BD%BF%E7%94%A8%20-newermt%20%E5%92%8C%20-exec%20ls%20%7B%7D%20%E6%97%B6%20bash%20find%20%E7%9A%84%E8%A1%8C%E4%B8%BA.png)
我有这个命令:
find /var/cache/pkg -newermt 2020-01-30 | grep 'kdeaccessibility-4.14.3_1'
它什么都没返回。我把它改成这样:
find /var/cache/pkg -newermt 2020-01-30 -exec ls -D '%F' -l -t -r {} \; | grep 'kdeaccessibility-4.14.3_1'
返回结果如下:
-rw-r--r-- 1 root wheel 556 2017-07-14 kdeaccessibility-4.14.3_1-6dc124e39c.txz
lrwxr-xr-x 1 root wheel 40 2017-07-21 kdeaccessibility-4.14.3_1.txz -> kdeaccessibility-4.14.3_1-6dc124e39c.txz
因此,该-newermt
选项似乎被该-exec
选项禁用。但我不明白为什么。
但是,如果我添加该-type f
选项,则查找工作就会按预期进行。
find /var/cache/pkg -type f -newermt 2020-01-30 -exec ls -D '%F' -l -t -r {} \; | grep 'kdeaccessibility-4.14.3_1'
没有返回任何内容。我由此推断,符号链接的存在导致了这种行为,但我不明白为什么。
答案1
我认为问题在于您的find ... -exec ls ... {} \;
(没有-type f
在find
参数列表中)也会对任何匹配的目录运行ls
,从而ls
列出这些目录的全部内容(除非您将该-d
选项添加到ls
参数列表中)。