Using `find` for multiple file extensions
Use the -o
option for an OR. For example, this would list .cpp
, .c
and .h
files:
find . -name \*.cpp -o -name \*.c -o -name \*.h
You will need to use the -o option. For example the statement below finds all png, jpg and gif files in a folder.
find . \( -iname \*.png -o -iname \*.jpg -o -iname \*.gif \)
I use the -iname option so that the match is case insensitive.
$ find /path/ -name '*.cpp' -or -name '*.c' -or -name '*.h'
The “-or” says I’m looking for either/both of two sets.
I recently wrote a quick guide to using find with boolean operators here: http://jamesfishwick.com/2012/linux-find-and-boolean-operators