Skip to content
Clairos Learn

Text and logs · Lesson 7 of 38 · 8 minutes

Pipeline counts

Filter logs through safe text pipelines.

Mastery 0/3Run itExplain itApply it
learner@clairosSimulated Linux lab
learner@clairos:~ $
↑ history · Tab complete · Ctrl+C cancel · Esc, Tab to leaveExit 0

Understand the pattern

Pipelines are a daily Unix skill for triage and reporting.

cat
Read one or more files to standard output without editing their contents.

Reading a source file should precede changing it; avoid printing real secrets.

grep
Select input lines that match a pattern; -i ignores case, -n adds line numbers, and -v inverts selection.

No matches is exit status 1, which is different from a malformed invocation.

wc
Count input. -l counts newline characters, -w counts whitespace-delimited words, and -c counts bytes.

Text without a final newline may have fewer counted lines than visible rows.

journalctl
Read the training journal by unit or a bounded line window.

A relevant unit and time range are more useful than an unfiltered wall of logs.

sort
Order lines before comparing or grouping them; -n compares numerically and -r reverses order.

Alphabetical sorting is not numeric sorting.

uniq
Collapse adjacent duplicate lines; use sort first when duplicates are not already together.

uniq does not find every duplicate in an unsorted stream.

Worked example and expected result
$ cat /var/log/auth.log | grep denied | wc -l
2

Exit status: 0. The command completed successfully in the training fixture.

$ journalctl -u ssh | grep refused
May 26 08:18:33 clairos-learn sshd[118]: password authentication refused
May 26 08:21:44 clairos-learn sshd[141]: root login refused by policy

Exit status: 0. The command completed successfully in the training fixture.

$ cat /home/learner/data/ports.txt | sort | uniq
22
23
443
80

Exit status: 0. The command completed successfully in the training fixture.

Try a variation

Repeat this workflow in the sandbox with a different scratch filename. Keep the system fixtures unchanged and compare the observed output with your expectation before moving on.

Explain it

In “Pipeline counts”, which interpretation is safe?

Apply it elsewhere

Before adapting the journalctl workflow from “Pipeline counts” to another server, what should you do?

Keep the momentum.

Complete the lab, then explain and apply the pattern.

Next: Port text reviewTry an incident drill

Anonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.

Keep learning

  1. 01Case-insensitive searchFind text regardless of capitalization.Practice
  2. 02Port text reviewRead, sort, and count a training port list.Practice
  3. 03Config text compareUse grep and diff to compare two config snapshots.Practice