Linuxlab

Chapter 7

Streams, redirection, pipelines

Updated July 3, 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 > sign silently wipes a file if it already exists. That is a common way to lose data: one typo and the file you needed is overwritten. The guard is noclobber mode:

$ set -o noclobber       # now > will 
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