Filtering with grep
Concept & Overview
Imagine looking through a massive, thousand-page logbook to find every time a system error occurred. Doing this manually would take hours! In Linux, we use grep as our digital magnifying glass to search for specific words or patterns instantly.
- The grep command filters files or piped text, printing only the lines that match your search word. For example, running grep "ERROR" logs.txt scans the file and extracts only the lines containing "ERROR".
logs.txt for all lines containing [ERROR] and save them into a new file named errors.log.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
grep "[ERROR]" logs.txt | Search logs.txt for lines containing [ERROR] |
grep "[ERROR]" logs.txt > errors.log | Save matching errors into errors.log |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Use the "grep" command to search logs.txt
- ○Create file "errors.log" in home directory
- ○Verify errors.log contains only [ERROR] entries
Ready to complete Quest 26?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.