Find text inside a file
Search text with grep
⏱ Est. ~5 min
01 · Read
Real files can have hundreds of lines. Instead of reading them all, grep lets you search for specific text and only show the matching lines.
💡 Picture thisLike pressing Ctrl+F (Find) in a document — type what you want, and only the matches light up.
Key points
- grep searches for a pattern inside a file
- It prints only the matching lines
- Syntax: grep "what to find" filename
02 · Terminal exercise
grep searches for text inside a file. It shows every line that contains your search term.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
Try searching for something else. How many console.logs are in the file?
(This section is interactive — please enable JavaScript.)
04 · Terminal exercise
Engineers often leave TODO comments as reminders. Let's find them.
(This section is interactive — please enable JavaScript.)
05 · Terminal exercise
What if you're not sure about the case? The -i flag makes grep ignore case.
(This section is interactive — please enable JavaScript.)
06 · Fill in the blank
To find 'error' in a file while ignoring case (so ERROR, Error, error all match), add the ___ flag to grep.
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.