Process text with Linux commands
Linux becomes powerful when small commands are connected. A pipe sends one command's standard output into another command's standard input.
Start with one command
cat /etc/passwd head -n 5 /etc/passwd grep 'root' /etc/passwd
head limits output while grep selects lines matching a pattern. In LinuxTerminal, use the simulator's available files for practice.
Build a pipeline
cat file.txt | grep 'error' | sort | uniq
Read this from left to right: produce text, keep matching lines, sort them, then collapse adjacent duplicates. This “small tools” approach is central to shell work.
| Tool | Typical job |
|---|---|
grep | Filter lines by a pattern |
sort | Order lines |
uniq | Remove adjacent duplicates or count them |
cut | Select fields or character ranges |
wc | Count lines, words and bytes |
Practice method: First run each command alone. Then add one pipe at a time and predict how the output changes.