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.

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
add comment

4 Answers

This should work:

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

I would use:

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

Quick and dirty, and avoids directory names:

find . -type f -name *.[c\|h]
share|improve this answer
1  
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
add comment

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.