Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted
find . -name '*.mp3' -o -name '*.jpg' -print
share|improve this answer
    
It seems the closest way to get rid of \-escaping and make code cleaner. Thanks for sharing! –  user52151 Nov 21 '12 at 13:50
add comment

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.

share|improve this answer
add comment
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
share|improve this answer
    
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
add comment

Your Answer

 
discard

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.