Search for text inside files
Read-only
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Recursively searches file contents for a string, showing each matching file and line — the standard way to find where something is defined, configured, or logged.
filessearchgreptext
Parameters
Directory to search under.
Text to search for inside files.
Commands
Show every line containing the text, with file name and line number
grep -rn -e "<text>" "."Verification
grep -rln -e "<text>" "." | wc -lA count of files containing the text; zero means no matches.
Undo
Not undoable
This recipe only reads file contents and changes nothing.
Pitfalls
- grep treats the search text as a regular expression; add -F to match it literally.
- Binary files produce "matches" noise; add -I to skip them.
- Searching a repository? git grep is faster and skips ignored files automatically.