Search For Specific Files Containing Specific Text in Linux

Here’s a cool technique I learned from a colleague during my development at work.  It basically gets a list of files from find and for each <filename>.<extension> found, searches for <search string>. You also have to option to include (exclude?) an <exclude path>.

Syntax:

find <start path> -name <filename>.<extension> -exec grep -li "<search string>" {} \; | egrep -v <exclude path>

For example:

find /www -name \*.php -exec grep -li "hello, world!" {} \; | egrep -v /www/html/downloads