up previous next contents
Next: Example 3-3: Redirection Examples. Up: Combining UNIX Commands Previous: Combining UNIX Commands   Contents

Character Streams, Standard Input, Output, and Error

UNIX commands are designed to work with "character streams". Each command that generates output, such as ls, prints its output as a stream of characters on what is known as the "standard output".

If an error is generated when a command is run, the error message is printed to the "standard error" device.

Many commands that accept input read their input from the "standard input" device.

There are default values for each of these devices:

Table 3-1:  Character streams and I/O devices.

Character Stream  Physical Device
standard input  keyboard
standard output monitor
standard error  monitor

Each of these devices are defaults, and defaults only. They can be changed easily, and often are. Changing the devices for the standard input, output, and error is known as "redirecting the flow" of commands. This is a very powerful feature of the UNIX operating system.

The following special characters are used to redirect the standard input and output of UNIX commands:

Standard Input/Output Redirection Symbols

Table 3-2:  I/O Redirection Symbols.

Redirection Symbol  Physical Device
>   Send the "standard output" character stream that results from a command to another location.  The default is for the standard output to be displayed on your computer monitor.  If the new location is a filename, create the file.
>>  Same as above, but if the new location is a file, append the information to the end of that file.
<   Redirect the standard input.  The UNIX command to the left of the symbol will read from the location specified to the right of the symbol, instead of from the keyboard.

The use of these symbols is best shown by example.


up previous next contents
Next: Example 3-3: Redirection Examples. Up: Combining UNIX Commands Previous: Combining UNIX Commands   Contents