Posted 2020-08-14 with tags grep, linux utilities

When searching with grep it is often desirable to show only the filenames which contain matches, instead of showing the match in situ (which sometimes floods the console with output depending on file contents). Use the -l option to return only the names of files which contain a match.

Examples

grep -l 'search-token' .

A more complicated real-world example handy for searching within a Laravel codebase:

grep -rl 'table->boolean' --exclude-dir={vendor,storage,.git,assets,node_modules,public,tags} --exclude=tags --exclude=composer.lock

which also uses the recursive search option -r and some exclude capabilities of grep to narrow down what's searched.

From the man Page

https://www.gnu.org/software/grep/manual/grep.html

-l
--files-with-matches

    Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of each file stops on the first match. (-l is specified by POSIX.)