views:

182

answers:

2

In the bash command line, I want to find all files that are named foo or bar. I tried this:

find . -name "foo\|bar"

but that doesn't work. What's the right syntax?

+8  A: 

You want:

find . \( -name "foo" -o -name "bar" \)

See the wikipedia page (of all places)

Mark Pim
A: 

I am cheap with find, I would use this:

find ./ | grep -E 'foo|bar'

Thats just my personal pref, I like grep more than find because the syntax is easier to 'get' and once you master it there are more uses than just walking file tree.

Shane C. Mason
I like the syntax. Why was he voted down? Is it inefficient? What does dot slash do?
It would also find all files in directories which contain foo or bar as a substring.
starblue
find dot should be sufficient. If you are using GNU find, then even the dot can be omitted.
sigjuice
It would, but that is pretty easy to deal with by using the handy regex expressions...
Shane C. Mason