Grep
Grep is a command-line tool for searching inside text files, like code.
Mac’s built-in search is mostly for filenames and reads only certain file types. Grep works with all text files and searches inside them. Here's how you can get started.
Search for “word” in the current folder.
grep "word" .
Search recursively, from current folder and its subfolders.
grep -r "word" .
Search inside a file.
grep "word" filename.txt
Show only the names of files that contain the search term.
grep -l "word" .
Make the search case-insensitive. It finds “word”, “Word” or “WORD”.
grep -i "word" .
Grep is a powerful tool and has many features. Type “man grep” in Terminal to learn more.