for it: one for input, one for output, and one for error messages. Typically,
these are attached to the user’s terminal (so they take input from or give
output to the command line), but they can be directed elsewhere, such as to or
from a file. These three streams are referred to and abbreviated as shown here,
and each of these is assigned a number, shown in the third column:
Stream AbbreviationNumber
Standard input stdin^0
Standard output stdout^1
Standard error, or error streamstderr^2
In the earlier section “Redirecting Output and Input,” you learned how to
redirect input and output without needing to know about stdin or stdout.
In addition, you can redirect where the stderr messages are sent and also
do some more powerful things.
If you are running a program and want any error messages that appear to be
directed into a text file instead of having them printed on a screen that might
not be monitored, you can use the following command when starting the
program or running a command (substitute program with the name of the
program or command you are running):
Click here to view code image
matthew@seymour:~$ program 2> error.log
Here, any error messages from program are added to the end of a file named
error.log in the current working directory.
If you want to redirect both stderr and stdout to a file, use the
following:
Click here to view code image
matthew@seymour:~$ program &> filename
You can do the same thing by using the following:
Click here to view code image
matthew@seymour:~$ program >> filename 2>&1
In this case, any output from program is added to the end of a file named
filename.
To redirect stderr to stdout, so that error messages are printed to the