9

In bash shell ls can use a logical OR functionality through (of course I could also do ls name1 name2 but my true examples are more complicated):

ls @(name1|name2)

Is there a way to do this using find?

My naive implementation:

find . -maxdepth 1 -name @("name1"|"name2") 

doesn't work (it just outputs nothing)

  • 4
    Did you read the OPERATORS section of the find manpage? – steeldriver Jul 1 '15 at 12:44
16

You can use -o for logical OR. Beware however that all find predicates have logical values, so you'll usually need to group ORed things together with parens. And since parens also have a meaning to the shell, you'll also need to escape them:

find /some/dir -maxdepth 1 \( -name '*.c' -o -name '*.h' \) -print
5

To answer your question, you can use -o option:

   expr1 -o expr2
          Or; expr2 is not evaluated if expr1 is true.

   expr1 -or expr2
          Same as expr1 -o expr2, but not POSIX compliant.

like this:

$ find . -maxdepth 1 -name "name1" -o -name "name2"
./name1
./name2

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.