What it is
Standard input, standard output, and pipelines (|) let small focused tools compose cleanly without creating temporary files or altering logs. Commands like head, tail, grep, sort, uniq, and wc filter and summarize thousands of log lines in seconds.
Why you need it
Opening a 2 GB production log in an interactive editor can freeze a host or accidentally modify evidence. Streaming filters keep inspection read-only and repeatable.
How it works
- Inspect the shape of a file safely with head or tail before searching everything.
- Filter matching lines with grep (adding -i for case-insensitive or -v to invert).
- Pipe matches into sort | uniq -c | sort -r to rank frequent offenders, or wc -l to count.
- Save sanitized summaries without copying raw tokens or passwords.
Counting and ranking failed logins via pipes
grep "FAILED_LOGIN" /var/log/auth.log | wc -l
grep "FAILED_LOGIN" /var/log/auth.log | sort | uniq -c | sort -rEach stage passes standard output to the next command’s standard input. uniq collapses adjacent duplicates, which is why sorting first is essential.
Practice ls -la, chmod, grep | wc, df -h, df -i, du, lsof, and ss -tulnp against five live troubleshooting missions.
Good practices and why
- Always sort before uniq -c so identical non-adjacent rows combine accurately.
- Keep original log files untouched; redirect sanitized findings to a separate note or /tmp artifact.
Common mistakes
- Running uniq without sort first and wondering why counts stay at 1.
- Pasting unfiltered log lines containing Bearer tokens into bug tickets.
Try it yourself
Complete Mission 2 in the Linux CLI Lab: count FAILED_LOGIN entries in /var/log/auth.log, spot the leaked Bearer line, and write only the sanitized user ID to /tmp/triage-user.txt.
What a successful result looks like
Your pipeline reports exact failure counts and /tmp/triage-user.txt contains the user ID without any secret token.
0 / 6000 characters · Saved on this device. Do not include passwords or private data.
Check your understanding
Answer the understanding check correctly to record exercise completion.
Related interview practice
These scenarios add constraints and follow-up questions to the concepts you just learned.
Further reading
Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.