Sometimes you will need to execute a command, but you don't want the output displayed to the screen. In such cases you can discard the output by redirecting it to the file /dev/null:
$ command > /dev/null
Here command is the name of the command you want to execute. The file /dev/null is a special file that automatically discards all its input.
To discard both output of a command and its error output, use standard redirection to redirect STDERR to STDOUT:
$ command > /dev/null 2>&1
Here 2 represents STDERR and 1 represents STDOUT. You can display a message on to STDERR by redirecting STDIN into STDERR as follows:
$ echo message 1>&2
Redirection Commands:
Following is the complete list of commands which you can use for redirection:
Command | Description |
pgm > file | Output of pgm is redirected to file |
pgm < file | Program pgm reads its input from file. |
pgm >> file | Output of pgm is appended to file. |
n > file | Output from stream with descriptor n redirected to file. |
n >> file | Output from stream with descriptor n appended to file. |
n >& m | Merge output from stream n with stream m. |
n <& m | Merge input from stream n with stream m. |
<< tag | Standard input comes from here through next tag at start of line. |
| | Takes output from one program, or process, and sends it to another. |
Name:Xr
Date:2014-06-01 17:01