stdin, stdout, stderr — Streams, Pipes and tee
Linux tools are deliberately small. sort only sorts, and wc only counts. The power comes from connecting them: the output of one flows straight into the next, with no temporary files in between. To connect them well, you need to know the three channels every program has.
The rule
In on 0, out on 1, errors on 2; a pipe joins 1 to 0.
Every process starts with three open streams, each with a number called a file descriptor:
| Number | Name | Default |
|---|---|---|
| 0 | stdin, standard input | the keyboard |
| 1 | stdout, standard output | the screen |
| 2 | stderr, standard error | the screen |
stdout and stderr both show up on the screen, but they are separate channels. That's why the redirects you learned earlier can split them apart (> for 1, 2> for 2).
The pipe, written as a vertical bar between two commands, connects the stdout of the left command to the stdin of the right one. For this whole section, Asha's data lives in ~/garden/harvest.csv:
date,crop,kg,picker
2026-06-01,tomato,3.5,asha
2026-06-01,basil,0.4,ravi
2026-06-02,tomato,2.0,ravi
2026-06-03,chilli,0.8,asha
2026-06-03,tomato,4.1,meera
2026-06-04,basil,0.6,asha$ cat harvest.csv | wc -l # 7 lines
$ grep tomato harvest.csv | wc -l # 3 tomato rowsOnly stdout goes through a pipe. Error messages still go to the screen unless you add 2>&1 before the pipe.
tee is a T-junction for a pipeline: it copies its stdin to a file and passes it on to stdout, so you can save a middle stage and keep going:
$ grep tomato harvest.csv | tee tomatoes.csv | wc -l
3Now tomatoes.csv holds the three tomato rows, and the count still appears. tee -a appends instead of replacing.