Wednesday, August 01, 2007

Linux note: how to disable output

One way is adding a redirection to the command to execute:

command >/dev/null

In the above line, command is executed with its output redirected to /dev/null.

More notes about the above syntax. ">" is the operator to direct the output of command to a file. In this case, the file is the special device /dev/null. The standard output (using ">") and the error output ("2>") can both be redirected. To redirect the standard output and the error output at the same time, use ("&>"), and to append the redirected output to a file, use (">>").

Disabling output is necessary in many situations. For example, when using nohup, the system output is put into the file nohup.out. If the disk space is limited, we may want this file to be as small as possible. Therefore, we may put necessary information into the error output, and redirect the standard output to null.

No comments: