The path
⌨️ Terminal TricksLesson 8 of 30 6 min 35 XP

🔗Pipes: passing work down a line

The | symbol hands one command's output straight to the next command.

Imagine an assembly line. One robot catches the fish, the next one cleans it, the next one cans it. In Linux, the | symbol joins commands into an assembly line.

🐧 Tux tells a story

Why this is a superpower

Each command does one small job extremely well. Pipes let you snap those small jobs together to do something big, without writing any program.

Commands in this lesson

cat notes/todo.txt | wc -lRead a file, then count its lines
3
cat penguins/facts.txt | grep penguinRead a file, then keep only matching lines
There are 18 kinds of penguin.
ls | sortList the folder, then sort the names
notes
penguins
welcome.txt
history | tail -3Take your last three commands

💡 Think of it like this

A pipe is literally a pipe. Whatever the left command shouts goes down the pipe, and the right command catches it.

🔬 The grown-up version

A pipe connects stdout of the left process to stdin of the right one, with no temporary file in between. Long pipelines such as ps aux | grep nginx | awk '{print $2}' | xargs kill are how experienced users solve problems in one line.

Now you try

This terminal is pretend, so you cannot break anything. Tap a chip or type a command yourself.

tux — bashpractice

Try the commands from this lesson. Type one and press Enter, or tap a chip below.

penguin@tux:~$
try

Quick check

What does the | symbol do?

How do you count the lines in a file using a pipe?

Finished this one?

Mark it done to collect 35 XP and keep your streak growing.