Find All Files Containing a Specific Text on Linux or macOS

by:

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.

1. Find All Files Containing a Specific Text Using grep

Use the command below to find all files containing a specific substring (YOUR_TEXT_TO_FIND).

$ grep -Hrn YOUR_TEXT_TO_FIND *

2. 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

3. More Resources