Find All Files Containing a Specific Text on Linux or macOS

onestop_databy:

Unix

This short tutorial teaches you how to find all files containing a specific text on linux or macOS using either the command find or grep.

Find All Files Containing a Specific Text Using grep

Within a directory, use the command below to find all files containing a specific substring (YOUR_TEXT_TO_FIND).

$ grep -Hrn YOUR_TEXT_TO_FIND *

Find All Files Containing Specific Text Using find

Besides the command grep itself, it can be combined with the command find to find substrings (YOUR_TEXT_TO_FIND).

$ find . -type f -print | xargs grep YOUR_TEXT_TO_FIND

More Resources