In Bash shell, it is possible to redirect output and errors of a command to /dev/null
in order to discard the command’s standard output and standard error streams. This can be useful to suppress any unwanted output, such as debugging information, or to run a command in the background without displaying output.
To redirect the standard output and standard error streams of a command to /dev/null
, use the following syntax:
command > /dev/null 2>&1
Here, command
is the command whose output and errors are to be discarded. The >
symbol redirects the standard output stream of the command to /dev/null
, while 2>&1
redirects the standard error stream to the same location as the standard output stream (i.e., to /dev/null
).
For example, to run the ls
command and discard its output and errors, you can use:
ls > /dev/null 2>&1
This will execute the ls
command and redirect its output and errors to /dev/null
, effectively discarding them.