3

I had a question using the "-o" option in find to find multiple extensions.

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

In the above I want to delete all files of two extensions that are older than a certain time. By using -o to list multiple names, does the -mtime only apply to the second or are older jpgs also excluded?

Thanks

Mureinik
  • 297,002
  • 52
  • 306
  • 350
user1490083
  • 361
  • 2
  • 7
  • 21
  • Don't know, put brackets around the or then it will be ok whichever way, `find "DIRECTORY" -type f \( -name \*.jpg -o -name \*.html \) -mtime +95` – ctrl-alt-delor Dec 16 '13 at 17:59

2 Answers2

2

You can solve this with parentheses:

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

find operators are evaluated in order of precedence. From the manual:

 ( 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.
sanmiguel
  • 4,580
  • 1
  • 30
  • 27
0

It only applies to second argument, just did a manual check real fast

user1490083
  • 361
  • 2
  • 7
  • 21