$ cat "

Quick Tip: Finding File Names of all Files in a Directory Containing a Given String


Here is a quick example of how to use grep to find the file names of all files in a directory tree which contain a given string:

grep -rl --include=*.js "string to search for" /some/path

-r makes the search recursive.
-l tells grep to list the file names rather than all occurrences in all the files, which is handy if you want to pipe the output to another command which will do something with those files.
--include specifies a pattern used to determine if a given file should be searched. If you want to specify multiple patterns you can surround them with curly braces, like so:

grep -rl --include={*.js,*.html} "string to search for" /some/path

Written by Erik Öjebo 2013-12-25 12:50