Chapter 03 of 17
Compose tools with streams
Use standard input, standard output, and pipelines to turn small commands into useful workflows.
The mental model.
Every process starts with standard input (descriptor 0), standard output (1), and standard error (2). A pipe connects stdout from the left command to stdin of the right command. Error messages normally remain visible in the terminal.
grep selects matching lines; wc counts; sort orders lines; uniq collapses adjacent duplicates. sort | uniq -c counts repeated values because sorting places equal lines together. LC_ALL=C can make real-system sorting predictable across locales.
A pipeline passes bytes rather than table objects. A filename containing whitespace can break naive xargs processing. On real GNU tools, find -print0 paired with xargs -0 preserves filename boundaries.
Inspect a pipeline one stage at a time. First confirm the input, then the filter, then aggregation. This isolates the stage that loses data instead of guessing at the full command.
Read it. Predict it. Try it.
Before running these commands, predict what each line will change or print. Launch a quest below to open the simulated terminal.
cat /var/log/syslog
grep "WARNING" /var/log/syslog
grep "WARNING" /var/log/syslog | wc -lRead the source, isolate warning lines, then count them. The last result is a count of matching lines, not necessarily the number of separate incidents.
Check your understanding
Explain the why.
Put it into practice.
Complete the exercises, then try the Boss Challenge without hints. Each quest checks its own objectives. You can revisit this chapter at any time.
Make the learning stick.
Close the explanation and describe the main idea in your own words. Change a filename or input and predict the outcome. Tomorrow, repeat a quest without hints. Then apply it in a disposable real Linux environment.
Open the real-system labs →