Redirection of command output to the bit bucket

On a GNU/Linux system there are 3 standard sources for input and output called:

  STDIN  (Standard IN)    = keyboard by default
  STDOUT (Standard OUT)   = screen by default
  STDERR (Standard ERROR) = screen by default

These can be referred to by the numbers:

  0 = STDIN
  1 = STDOUT
  2 = STDERR

To redirect the output of a program to /dev/null use the > redirector

wobble > /dev/null

This will redirect the information from the wobble program away from the screen to the null device; /dev/null.

However this does not redirect the errors, they would still be output to the screen. To also redirect errors we must:

wobble > /dev/null 2>&1

What this does is redirect STDOUT to /dev/null and it also redirects STDERR (2) to wherever STDOUT (1) is going, currently /dev/null.

Back to GNU/Linux Command Line Tips