Unix find: multiple file types

Jacko picture Jacko · Aug 25, 2011 · Viewed 66.3k times · Source

I want to run find -name with multiple file types. Eg.

 find -name *.h,*.cpp

Is this possible?

Answer

Eric Wilson picture Eric Wilson · Aug 25, 2011
$ find . -name '*.h' -o -name '*.cpp'

To find this information in the man page, type man find and the search for operators by typing /OPERATORS and hit enter.

The . isn't strictly necessary with GNU find, but is necessary in Unix. The quotes are important in either case, and leaving them out will cause errors if files of those types appear in the current directory.

On some systems (such as Cygwin), parentheses are necessary to make the set of extensions inclusive:

$ find . \( -name '*.h' -o -name '*.cpp' \)