Linux grep and ripgrep Cheat Sheet/Only search matching file names

Restrict recursive search to certain extensions.

Section: Recursive Search

Only search matching file names

bash
bash
grep -R --include='*.ts' 'useEffect' src/
Explanation

Helpful for codebases containing mixed file types.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Recursive Search
Search recursively
Search all files under a directory.
OpenIn sheetbashsame section
Recursive search with line numbers
Show file names and line numbers for matches.
OpenIn sheetbashsame section
Exclude directories
Skip noisy folders like node_modules or dist.
OpenIn sheetbashsame section
List matching file names only
Show only files that contain a match.
OpenIn sheetbashsame section
Search for a word
Print lines containing a pattern.
OpenIn sheetbash1 tag match
Use extended regex
Enable `+`, `?`, and alternation without heavy escaping.
OpenIn sheetbash1 tag match