Bash – Get list of all files by mask in terminal

bashfile searchfindterminal

I want to find all *.h,*.cpp files in folders with defined mask, like */trunk/src*. So, I can find separately *.h and *.cpp files:

find . -path "*/trunk/src/*.h"
find . -path "*/trunk/src/*.cpp" 

What is the best way to get the file-list both of types (*.h and *.cpp)?

PS I'd like to pipe the list to grep.

Best Answer

You can use -o for "or":

find . -path '*/trunk/src/*.h' -o -path '*/trunk/src/*.cpp'

which is the same as

find . -path '*/trunk/src/*' \( -name '*.h' -o -name '*.cpp' \)

If you want to run grep on these files:

find . \( -path '*/trunk/src/*.h' -o -path '*/trunk/src/*.cpp' \) -exec grep PATTERN {} +

or

find . -path '*/trunk/src/*' \( -name '*.h' -o -name '*.cpp' \) -exec grep PATTERN {} +
Related Question