Juicy lil' bytes

How to Use Grep to Find File Names With a Matching String

By default, grep displays the lines in one or more files that match your search string (or regular expression). Here is how you recursively search through a directory of files and list the name(s) of the files that contain a matching string instead of the matched line.

grep -l Switch

The -l switch indicates that you want to display the names of files that contain a string that matches your query. Here is an example of its use with an entire directory of JavaScript files (using the *.js wildcard):

grep -l 'SEARCH TERM' *.js

This command causes grep to search for lines that match the query SEARCH TERM in every .js file in the working directory. The application will print the names of the files that contain a match to the standard output stream.

Replace SEARCH TERM with your query and *.js with any filetype or the names of a set of files that you would like to search. The query can be a string or regular expression.

grep Documentation

Here is the link to the grep documentation on this switch.