19

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)

JeffDror
  • 325
  • 1
  • 2
  • 7

2 Answers2

26

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
Toby Speight
  • 8,460
  • 3
  • 26
  • 50
lcd047
  • 7,160
  • 1
  • 22
  • 33
10

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
mhi
  • 3
  • 2
Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68