Skip to content
BENIBIX Learn

Pipe (|)

Infrastructure⌨️ Linux & the Command LineCommand Line

Also known as Pipe Operator, Shell Pipe, Pipeline (Shell)

The | sign. It sends what one command prints into the next command.

Think of it like

Think of it like a water pipe between two sinks. What drains out of one flows into the next.

Example

Emma has a long list of names. She pipes it into sort, and the names come back in order.

Why it matters

Small commands each do one job. A pipe joins them, so you rarely need a big program.

Definition

A pipe sends what one command prints into the next command. You write it as a straight bar, |, between the two commands. The first command does not print to the screen. Its output flows into the second one instead. You can join many small commands this way to do one bigger job.

Example code

console
$ printf "pear\napple\nfig\n" | sort
apple
fig
pear
Three words flow through the pipe into sort, and come out in order.
Each command passes its output to the next through the pipe. Only the last one prints to the screen.

Common mistake

Mixing up | and >. A pipe feeds another command, and > writes into a file.

Key takeaways

  1. 1
    Output to input. One command feeds the next.
  2. 2
    Small tools. Each command does one job.
  3. 3
    Chain many. Join as many as you need.

Learn it properly