Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
use -o option as, find . -name ".cpp" -o -name ".h" -print – thegeek Jul 6 '10 at 9:57
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

Use -o; see the examples here.

share|improve this answer
I think this should be the accepted answer. – feuGene Jul 22 '15 at 18:57

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
I think this is way too much information for this question. – feuGene Jul 22 '15 at 19:00


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

Your Answer


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.