Linux Bash: How to find a string inside C/C++ Source and Header Files


Just issue the following in the folder of the source codes and replace ‘FIND ME’ with the string you want to query:

find -O3 . -regex '.*\.\(c\|cpp\|h\)$' -exec grep 'FIND ME!' -sl '{}' \;

You can change the contents of the regular expression to search in different file extensions (file types). 

Leave a Reply