Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run this command...

sudo find /storage -name "*~" -or -name ".*~" -or -name "#.*#"
-or -name ".DS_Store" -or -name "Thumbs.db"

... it gives me a list of matching files, as expected. However, if I use this command...

sudo find /storage -name "*~" -or -name ".*~" -or -name "#.*#"
-or -name ".DS_Store" -or -name "Thumbs.db" -exec rm -v {} \;

... nothing is deleted. Similarly, with echo, nothing is printed...

sudo find /storage -name "*~" -or -name ".*~" -or -name "#.*#"
-or -name ".DS_Store" -or -name "Thumbs.db" -exec echo {} \;

How come?

share|improve this question
up vote 2 down vote accepted

You've got to group your expression correctly - currently the -exec only applies to the last -or branch.

sudo find /storage \( -name "*~" -or -name ".*~" -or -name "#.*#" -or -name ".DS_Store" -or -name "Thumbs.db" \) -exec rm -v {} \;

Just remember that -exec is just an expression that returns true if the command returns zero, so running the command is just a side-effect.

share|improve this answer
+1 Perfect! Thanks very much. – nbolton Jan 12 '10 at 22:16
especially note the escaped parentheses \( and \) -- this prevents the shell from interpreting them; in this case you want find to handle them as part of the expression. this and other good examples on the find manpage: – quack quixote Jan 12 '10 at 22:16
Seems my workaround wasn't necessary, works like a charm, cheers. – Jeffrey Vandenborne Jan 12 '10 at 23:02
@Douglas Leeder - Came across this example that helped me answer my own question at… however I don't quite follow the statement so running the command is just a side-effect. What do you mean by that exactly? – PeanutsMonkey Sep 15 '12 at 7:33
find Documents/ -iname '*.txt' -exec echo {} \;
 -or -iname '*.cpp' -exec echo {} \;

This however works. Hope this can help you further a little. If you use exec separately with all -or's the command will work.

I've found an alternative to your problem though.

for file in $(find Documents/ -iname '*.txt' 
-or -iname '*.cpp'| awk '{print $1}'); do rm $file; done
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.