Redirecting Standard I/O

Most UNIX commands invoke a special routine called standard output (or stdout) to display information. They invoke a different routine called standard error (or stderr) to display any error messages. There is a similar routine to get input called standard input (or stdin).

In the following example, mp0094 could not be listed, so an error message went to standard error (stderr):

dtr> ls mp0094 mp0095
ls: mp0094 not found: No such file or directory (error 2)
mp0095
dtr>

Here, mp0095 was found and listed to standard output (stdout). Using the standard error routine for error messages allows the shell to redirect the errors from the screen to a file, as in the following example:

dtr> ls mp0094 mp0095 2> myerrors mp0095 dtr> ...

Get Practical UNIX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.