Chapter 7

Streams, redirection, pipelines

Updated November 1, 2026

Every command has three standard streams: input (stdin, number 0), output (stdout, number 1), and the error stream (stderr, number 2). By default input is the keyboard, and output and errors go to the screen. These streams can be redirected.

$ echo "first line" > log.txt     # write output to a file (overwriting it)
$ echo "second line" >> log.txt   # append to the end of the file
$ ls /nope 2> errors.txt          # send errors to a file
$ sort < log.txt                  # take input from a file

The digit in front of > is the number of the stream being redirected. For stdout it is customary to leave it out: > is the same as 1>, and < is the same as 0<. For stderr t

Locked

The rest of this chapter is part of a paid course

You are reading the open part. Buy the course to read the whole chapter.

See the course