Advanced grep Flags (-i, -v, -r, -E)
Concept & Overview
While basic grep searches for exact strings, production log analysis requires powerful matching flags:
- -i: Case-insensitive search (matches error, Error, or ERROR).
- -v: Invert match (prints lines that do not match the given pattern, perfect for stripping noise).
- -r (or -R): Recursive directory search across all subdirectories and files.
- -E: Extended regular expressions (supports | alternation for multiple patterns, +, and parentheses without escape backslashes).
logs/:1. Run
grep -i "error" logs/app.log to match errors regardless of uppercase/lowercase.2. Run
grep -v "INFO" logs/app.log to filter out routine info lines.3. Run
grep -r "SSH" logs/ to recursively locate SSH activity across all log files in logs/.4. Run
grep -E "(WARNING|ERROR)" logs/app.log to match lines containing either WARNING or ERROR using extended regex.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
grep -i "error" logs/app.log | Case-insensitive pattern search |
grep -v "INFO" logs/app.log | Invert search (exclude lines matching pattern) |
grep -r "SSH" logs/ | Recursively search all files in directory |
grep -E "(WARNING|ERROR)" logs/app.log | Search with extended regex alternation |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Run case-insensitive grep (-i) on logs/app.log
- ○Run inverted grep (-v) to exclude INFO
- ○Run recursive grep (-r) across logs/
- ○Run extended regex grep (-E) with alternation
Ready to complete Quest 29?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.