This command will print the *.cpp filenames in the given directory:

find . -name "*.cpp" -print  

How can I print both *.cpp and *.h filenames?

link|improve this question

1  
use -o option as, find . -name ".cpp" -o -name ".h" -print – thegeek Jul 6 '10 at 9:57
feedback

3 Answers

up vote 2 down vote accepted

Try this:

find -regex ".*\.\(cpp\|h\)$"

An example with more alternatives:

find -regex ".*\.\(cpp\|c\|h\|o\)$"
link|improve this answer
feedback

Use -o; see the examples here.

link|improve this answer
feedback

I'll give an example. This will search for files with owner=1000 and write them to "uid.list", search for files with group=1000 and write them to "gid.list" and it will skip paths beginning with /proc, /sys, /dev. The advantage of combined conditions is that filesystem is scanned only once. Here it is:

find / \
\( \( -path "/proc" -or -path "/sys" -or -path "/dev" \) -prune \) -or \
\( \( -user 1000 -fprint "uid.list" \)  , 
   \( -group 1000 -fprint "gid.list" \) \)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.