使用find命令删除特定时间之前的多个文件扩展名

3

我有一个问题,在使用find命令的"-o"选项时,如何查找多个文件扩展名。

find "DIRECTORY" -type f -name \*.jpg -o -name \*.html -mtime +95

在上述情况下,我希望删除所有两种扩展名的文件,这些文件比某个特定时间旧。 通过使用-o列出多个名称,-mtime是否仅适用于第二个名称,还是较旧的jpg也被排除在外?
谢谢

不知道的话,把括号放在“或”周围,无论哪种方式都可以,find "DIRECTORY" -type f \( -name \*.jpg -o -name \*.html \) -mtime +95 - ctrl-alt-delor
2个回答

2
您可以使用括号解决这个问题:
find "DIRECTORY" -type f \( -name \*.jpg -o -name \*.html \) -mtime +95

find 操作符按照优先级顺序进行评估。来自手册:

 ( expr )
          Force precedence.  Since parentheses are special  to  the  shell,
          you  will  normally  need to quote them.  Many of the examples in
          this manual page use  backslashes  for  this  purpose:  `\(...\)'
          instead of `(...)'.

 expr1 expr2
          Two expressions in a row are taken to be joined with  an  implied
          "and"; expr2 is not evaluated if expr1 is false.

 expr1 -o expr2
          Or; expr2 is not evaluated if expr1 is true.

0

它只适用于第二个参数,我刚刚进行了手动检查


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接