Linux/Unix FAQ: On a Unix system, how do I redirect both STDOUT (standard output) and STDERR (standard error) to /dev/null, aka, “the bit bucket”?
Solution
To redirect both STDOUT and STDERR to /dev/null on Unix/Linux systems, use this syntax:
$ my_command > /dev/null 2>&1
With that syntax, my_command
represents whatever command you want to run, and when it’s run, its STDOUT output is sent to /dev/null (the “bit bucket”), and then the 2>&1
syntax tells STDERR to go to the same place as STDOUT.
Note that this syntax can be used to redirect command output to any location, but we commonly send it to /dev/null when we don’t care about either type of output, and at some point in Unix history the /dev/null file became known as the bit bucket because of this.
So if you needed to know how to redirect both STDOUT and STDERR to the bit bucket, I hope this is helpful.