Mission 8 of 30
Grep: Search Master
Find the important lines in a noisy application log.
Search text confidently with exact matches, case-insensitive matches, inverted matches, and simple regex.
Your outcome: You can find information instead of scrolling endlessly.
Practice inside
Practice inside
~/linux-practice. Check your setup before you begin.
Prerequisite: Pipes and Filters
.
What you’ll practice
- Use grep options
- Understand simple regex anchors
- Search recursively in practice files
The mental model
- grep prints lines matching a pattern.
- Regex is a pattern language; start small.
- -r searches folders recursively.
Try it in your terminal
Basic grep
Safe in practice folderFinds matching and non-matching lines.
Run from ~/linux-practice
cd ~/linux-practice
echo -e 'Apple\napple\nAPPLE\nBanana\napricot' > fruits.txt
grep -i 'apple' fruits.txt
grep -v 'apple' fruits.txt Regex anchors
Safe in practice folderUses start, end, and OR matching.
Run from ~/linux-practice
grep '^A' fruits.txt
grep 'e$' fruits.txt
grep -E 'apple|Banana' fruits.txt Recursive search
Safe in practice folderSearches through folders.
Run from ~/linux-practice
mkdir -p projects/search-demo
echo 'secret pattern' > projects/search-demo/file.txt
grep -r 'pattern' projects Put it into practice
- Create ips.txt and find addresses starting with 192.168.
- Use grep -n to show line numbers.
Check your result
Only the intended log lines appear.
Common mistakes
- You type `grep apple|banana file.txt` and get confused by the results. The shell sees the pipe symbol and tries to run two commands. Wrap your pattern in quotes: `grep 'apple|banana' file.txt`. Quotes tell grep, 'this whole thing is my search pattern.'
Check your understanding
Explain these in your own words. If you’re unsure, revisit the examples before moving on.
- Which option ignores case?
- What does ^ mean in a regex?
Your practice, your pace
Loading saved progress…