【问题标题】:Using find command to delete multiple extensions older than certaint time使用 find 命令删除超过特定时间的多个扩展
【发布时间】:2013-12-16 17:55:25
【问题描述】:

我有一个问题,使用 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

标签: linux shell find


【解决方案1】:

你可以用括号解决这个问题:

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.

【讨论】:

    【解决方案2】:

    它只适用于第二个参数,只是做了一个真正快速的手动检查

    【讨论】:

      猜你喜欢
      • 2012-02-11
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 1970-01-01
      • 2021-06-07
      相关资源
      最近更新 更多