Kolam Ayer MakersLinux Foundations

Pipes

Core Idea

A pipe connects stdout from one process to stdin of another process.

The pipe character | is shell syntax, not a command. Bash creates the pipe, starts both commands, and connects their file descriptors.

First Pipeline

history | grep ssh

Read it left to right:

Build Pipelines Slowly

history
history | grep ssh
history | grep ssh | wc -l

Add one stage only after the previous stage makes sense.

What Crosses The Pipe

Bytes cross the pipe. Usually those bytes are text lines, but the shell does not care. Tools such as grep, sort, uniq, cut, and wc cooperate because they can read stdin and write stdout.

Common Patterns

Count matches:

grep -R makers ~/src/pages | wc -l

Sort and deduplicate:

grep -R '^#' ~/src/pages | sort | uniq

Keep a copy while continuing the pipeline:

history | tee ~/playground/history.txt | grep ssh

Watch Out

Proof Check

Run a three-stage pipeline and explain exactly what each stage reads and writes.

Docs Pointers