Back to course

51. Introduction to Redirection: STDIN, STDOUT, STDERR

Linux Basics: From Zero to CLI Hero

Controlling the Flow of Data

In Linux, data flow is highly standardized. Every process (command) has three default data streams:

  1. STDIN (Standard Input): File Descriptor 0. The input the command receives (usually the keyboard).
  2. STDOUT (Standard Output): File Descriptor 1. The normal output the command generates (usually the screen/terminal).
  3. STDERR (Standard Error): File Descriptor 2. Error messages the command generates (usually the screen/terminal).

Redirection is the process of changing where these streams originate or terminate.

Output Redirection (>) - Overwriting

The > symbol redirects STDOUT to a file, overwriting the file's contents if it exists.

bash $ ls -l /etc > file_listing.txt

The output of ls is written entirely to file_listing.txt

Output Redirection (>>) - Appending

The >> symbol redirects STDOUT to a file, appending the new output to the end of the existing file.

bash $ date >> file_listing.txt

The current date is added to the end of file_listing.txt