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). 


This post is also available in: Greek

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.