Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
01Command
$ grep -rn "TODO" src/02What it does
-r recurses into directories, -n numbers the matching lines, and output is colored file:line:content on terminals. The pattern is a regular expression; quote it so the shell doesn't expand it. Useful add-ons: -i for case-insensitive, -l to list only file names, -w for whole-word matches, --include='*.py' to limit file types, and --exclude-dir=node_modules to skip noise. For literal strings pass -F so regex metacharacters like . or * match themselves. If results are huge, ripgrep (rg) is a faster drop-in alternative with these defaults built in.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- grep(1) — print lines matching a patternEvidence: The grep man page documents -r for recursive directory search and -n to prefix each output line with its 1-based line number.
Last verified: 2026-09-17 · Category: Developer
06Related solutions
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Generate a modern Ed25519 public/private key pair in ~/.ssh for authenticating to servers and Git platforms without passwords.
Add or remove read, write, and execute permission for the owner, group, or others using symbolic or octal modes.