DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
About files and directories

Redirecting standard output and standard error

Quite often within the UNIX environment, you will find strange constructs at the end of commands such as:

   2>/dev/null
or
   >/dev/null 2>&1
These are redirection commands used to redirect the output usually sent to standard output and standard error. When redirecting output in this way, ``2'' always represents standard error and ``1'' standard output. For example, the first construct (2>/dev/null) specifies that all error messages should be sent to the special file /dev/null.

The second construct is slightly more complex and is made up of two parts. The first part (/dev/null) specifies that all output normally sent to standard output should be redirected to the special file /dev/null. However, the second part of the construct also redirects standard error to standard output (2>&1). The result of this is that all output to both standard output and standard error are redirected to the special file /dev/null.

For example, the following command:

find / -type d -name etc -print 2>$HOME/foo

searches the entire directory tree for directories called etc. Any directories found by the command are displayed on the screen. Any error messages sent by the command are redirected from standard error to a file call foo in your HOME directory.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004