I trying to remove boring \-escaping from this command:

find . \( -name '*.mp3' -o -name '*.jpg' \) -print

by wrapping it in single quotes:

find . '( -name *.mp3 -o -name *.jpg )' -print

implying that arguments go straight to the find without any expansions.

However the output is different.

find . -name '*.mp3' -o -name '*.jpg' -print
  • It seems the closest way to get rid of \-escaping and make code cleaner. Thanks for sharing! – user52151 Nov 21 '12 at 13:50
  • This only prints *.jpg files, the parentheses were there for a reason. If you remove -print it will work on most systems. – Random832 Sep 26 '16 at 14:14

You could also use regular expressions, which in my opinion make this more concise and gives you better control:

find . -regextype posix-egrep -iregex '.*(pdf|mp3)$'

This finds all files (or directories, unless you specify -type f) that end in pdf or mp3.

find . '( -name *.mp3 -o -name *.jpg )' -print

This looks for all files in the directories named . and ( -name *.mp3 -o -name *.jpg ), which is probably not what you intended.

Use the single quotes just for the round brackets:

find . '(' -name '*.mp3' -o -name '*.jpg' ')' -print
  • Thanks for reply! Is it possible to move a little bit further with it and remove that cumbersome escapings? Ideally to have as little quotes as possible? – user52151 Nov 21 '12 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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