Frequently Asked Question

What does the pipe operator | actually do?

The | operator tells the shell to connect the standard output of the command on the left to the standard input of the command on the right. Under the hood the shell calls the pipe(2) system call, which returns two file descriptors, one for reading, one for writing, joined by an in-kernel buffer. The shell forks both commands, wires the writing end into the producer's fd 1 and the reading end into the consumer's fd 0, then runs them concurrently.

The two processes never share memory or write to disk. Bytes flow through the kernel buffer (typically 64 KB on Linux): when it fills, the producer blocks until the consumer reads; when it empties, the consumer blocks until more arrives. That natural back-pressure means you can stream gigabytes through a pipeline without ever materialising the intermediate output. It is the closest thing the command line has to a function composition operator.

Video

Further reading and video