Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I'd like to find source files (*.c, *.cpp, *.h) that contain in Linux/MinGW/Cygwin, and recursively in all sub directories.

My basic idea is using find and grep. However, building a regular expression that can check given file name is either *.c, *.cpp, or *.h isn't easy. Could you help me out?

share|improve this question

This should work:

find Linux/MinGW/Cygwin -name '*.c' -o -name '*.cpp' -o -name '*.h'
share|improve this answer
find -regex '.*/.*\.\(c\|cpp\|h\)$'
share|improve this answer

I would use:

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

Quick and dirty, and avoids directory names:

find . -type f -name *.[c\|h]
share|improve this answer
There are three problems with this command: 1. It won't find *.cpp files. 2. It will find *.| files. 3. The glob will expand if there are matching files in the current directory. Quoting prevents that. – Dennis Dec 17 '13 at 15:48

I use a mac pro which also works in bash. But every time I type in the command line:

find -name

it says illegal option. So I just simplified it as:

find *.c *.cpp *.h

and found it really worked!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .