Search across folders
Find text in any file with grep -r
⏱ Est. ~3 min
01 · Read
What if you want to find text but don't know which file it's in? grep -r recursively searches all files in a folder and all its subfolders.
💡 Picture thisRegular grep searches one file. grep -r is like opening every drawer in every cabinet in the whole building.
Key points
- grep -r searches all files in an entire directory tree
- Each match shows the filename and the matching line
- Great for finding where something is defined in a project
02 · Terminal exercise
What if you don't know which file the text is in? Search all files at once. The -r flag tells grep to recursively search every file in a folder.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
Now search across all files for 'localhost'.
(This section is interactive — please enable JavaScript.)
04 · Fill in the blank
To search for a word across all files in all subfolders, use: grep ___ "word" .
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.