The Pipe

What this is. A pipe connects the output of one command to the input of the next.

`

command1 | command2

`

Nothing touches the disk. The first command's results flow straight into the second, which is why pipelines are fast even on large inputs.

✦ The philosophy this comes from

Unix was built on a deliberate bet: rather than one program that does everything, make many small programs that each do one thing, and give them a standard way to be joined. grep does not sort. sort does not count. wc does not search. None of them needed to, because the pipe lets you assemble the one you need out of the ones that exist. Every command you learn multiplies with every other command you know.

The same job, two approaches

TEMPORARY FILES

grep ERROR app.log > tmp.txt
sort tmp.txt > tmp2.txt
uniq tmp2.txt > final.txt
rm tmp.txt tmp2.txt

A PIPELINE

grep ERROR app.log | sort | uniq
Compare → Both produce the same result. The pipeline touches no disk, leaves no mess to clean up, and reads as a single sentence describing the transformation. This is the difference the pipe makes.
SANKOFA SANDBOX
learner:~$

Build the pipeline one stage at a time and watch the output narrow.

Try it → Run `cat logs/app.log`, then add `| grep ERROR`, then add `| wc -l`. Adding one stage at a time is exactly how you should build every pipeline, because you can see what each stage receives.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: sort, uniq, and the Counting Pipeline →
← Back