tags:

views:

1032

answers:

4

I know that to find all the h files I need to use: find . -name "*.h" but how to find all the h AND cpp files?

+7  A: 
find . -name \*.h -o -name \*.cpp -print
Paul Tomblin
A: 

find -name ".h" -or -name ".cpp"

Philluminati
This only returns files whose names are exactly '.h' or '.cpp'. A wildcard is required to work as desired: find -name "*.h" -or -name "*.cpp"
lmop
+3  A: 

Paul Tomblin Has Already provided a terrific answer, but I thought I saw a pattern in what you were doing.

Chances are you'll be using find to generate a file list to process with grep one day, and for such task there exists a much more user friendly tool, Ack

Works on any system that supports perl, and searching through all C++ related files in a directory recursively for a given string is as simple as

ack "int\s+foo" --cpp

"--cpp" by default matches .cpp .cc .cxx .m .hpp .hh .h .hxx files

( It also skips repository dirs by default so wont match on files that happen to look like files in them )

Kent Fredric
A: 

find . -regex ".*.[cChH](pp)?" -print

This tested fine for me in cygwin.

-Lyles

Lyle Snodgrass