Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

find . -name "*.cpp" -print  

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

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

4 Answers 4

up vote 2 down vote accepted

Try this:

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

An example with more alternatives:

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

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" \) \)
share|improve this answer

Use:

find . -name "*.cpp" -print -o -name "*.h" -print
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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