Linux pipes and redirection: save a test log and filter it
Send test output to a file, catch the error messages too, and use pipes with grep, sort and uniq to find the most common failure.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a pipe with two outlets and two buckets. One outlet gives the normal water. The other gives the dirty water. Both usually pour into the same sink, so you cannot tell them apart. A bucket under each outlet keeps them apart. A pipe can also carry the normal water into the next machine.
The normal outlet is standard output. The dirty outlet is standard error. A bucket is a file. The pipe sign is |.
Tom, a tester at Daily List, a to-do list app, uses this to save a and to find the most common failure. Mei, the test lead, wants a count, not a screen full of text.
What it is: The shell is the program that reads your commands. are the two paths a command uses to print. Standard output is the normal results. Standard error is the error messages. are >>, which adds to a file, and 2>&1, which sends errors to the same place as normal output. A sort and count chain is several commands joined by pipes that count how often each line appears, biggest count first. Reading the log only on the screen is the nearest neighbour. The text scrolls away, and the two streams look the same.
Why it matters: A long test log is hard to search, and error lines mix with normal ones. If Tom cannot save both streams and count the repeats, he guesses which failure matters. Leo then chases the wrong line.
PLAIN WORDS · 1 in this section
- append
- add to the end of something
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A water pipe with two outlets and buckets.
- Outlets
- Buckets
- Pipe
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The clean-water outlet | Standard output |
| The dirty-water outlet | Standard error |
| A bucket that you empty first | The > sign |
| A bucket that you keep filling | The >> sign |
| A pipe to the next machine | The | sign |
WHERE THIS PICTURE STOPS
- Water is one stream, but a command can print many lines.
- A bucket only holds material; a combined log can interleave buffered streams and does not guarantee causal order.
- A pipe stops when the machine ends, but a log stays on disk.
HOOK
Two outlets, buckets and a pipe.
TELL A FRIEND
Two outlets, buckets and a pipe.
OFTEN MIXED UP WITH Linux part 2: processes, environment variables and scheduled jobs. That topic starts and stops programs. This one saves what they print and filters it.
Sources & standards — 3 sources
- Market practice
GNU Bash Reference Manual ↗ — GNU · Bash 5.2 publisher tagged source — Selected Pipelines, Redirections, Environment, Shell Scripts, special parameters, errexit, pipefail, ENV/BASH_ENV and kill.
Selected publisher sections read for Testing Tools audit. Bash 5.2 publisher tagged source. This is not live service testing or a full-publication certification.
- Market practice
GNU Coreutils manual ↗ — GNU · Coreutils 9.7 — Selected exit status, tail descriptor/name behavior, wc newline counts, uniq adjacency and chmod invocation.
Selected publisher sections read for Testing Tools audit. Coreutils 9.7. This is not live service testing or a full-publication certification.
- Market practice
GNU grep publisher manual source ↗ — GNU · Unversioned publisher source read 7 November 2026; VERSION placeholder is not a certified edition — Selected introduction, matching control, -n, -F and exit status: 0 match, 1 no match, 2 error, with -q exception.
Selected publisher sections read for Testing Tools audit. Unversioned publisher source read 7 November 2026; VERSION placeholder is not a certified edition. This is not live service testing or a full-publication certification.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
GNU Bash Reference Manual ↗ — GNU · Bash 5.2 publisher tagged source — Selected Pipelines, Redirections, Environment, Shell Scripts, special parameters, errexit, pipefail, ENV/BASH_ENV and kill.
Selected publisher sections read for Testing Tools audit. Bash 5.2 publisher tagged source. This is not live service testing or a full-publication certification.
- Market practice
GNU Coreutils manual ↗ — GNU · Coreutils 9.7 — Selected exit status, tail descriptor/name behavior, wc newline counts, uniq adjacency and chmod invocation.
Selected publisher sections read for Testing Tools audit. Coreutils 9.7. This is not live service testing or a full-publication certification.
- Market practice
GNU grep publisher manual source ↗ — GNU · Unversioned publisher source read 7 November 2026; VERSION placeholder is not a certified edition — Selected introduction, matching control, -n, -F and exit status: 0 match, 1 no match, 2 error, with -q exception.
Selected publisher sections read for Testing Tools audit. Unversioned publisher source read 7 November 2026; VERSION placeholder is not a certified edition. This is not live service testing or a full-publication certification.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.