Standered Input/Output in Linux.

Standered Input/Output

There are two different types of output:

1. Standard output (STDOUT)
2. Error output (STDERR)

STDOUT and STDERR can be selectively directed to specific files. This is useful when
trying to capture error messages as demonstrated below.


$ ls -l /NonExistantFile 1>ls.txt 2>lserror.txt
$ ls -l ls*
-rw-r–r– 1 nick nick 61 2009-06-10 11:46 lserror.txt
-rw-r–r– 1 nick nick 0 2009-06-10 11:46 ls.txt.

In this example, 1> represents STDOUT and 2> is for STDERR. Since the
requested file does not exist, an error message is logged in the lserror.txt
file. All non-error output is saved in the ls.txt file.


In addition to STDOUT and STDERR you can also redirect input from another
location (such as a file) to a command. This is known as standard input or STDIN.

The next example demonstrates using STDIN to feed the contents of a file to the
mail command

mail < ShoppingList.txt