PENTEST
How to list all source files (*.c, *.cpp, *.h)
remoted
2018. 3. 8. 15:50
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?
asked Feb 14 '11 at 18:25
This should work:
find Linux/MinGW/Cygwin -name '*.c' -o -name '*.cpp' -o -name '*.h'
answered Feb 14 '11 at 18:34
find -regex '.*/.*\.\(c\|cpp\|h\)$'
answered Feb 14 '11 at 18:37
I would use:
find . -regex '.*\.\(c\|cpp\|h\)$' -print
answered May 13 '11 at 15:49
Quick and dirty, and avoids directory names:
find . -type f -name *.[c\|h]
answered Dec 17 '13 at 14: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!
answered Nov 4 '14 at 14:55
You can use a slightly simpler regex:
find . -type f -regex ".*\.[ch]\(pp\)?$"
$
at the end of the command do? – Ali Aug 15 '17 at 3:16foo.cpp.old
for example). – Dennis Williamson Aug 23 '17 at 13:12