Sometimes you don’t want to save the output into a file; in fact, sometimes you don’t even want to see it at all.
Redirect the output to /dev/null as shown in these examples:
1 |
$ find / -name myfile -print 2> /dev/null |
or:
1 |
$ noisy >/dev/null 2>&1 |
We could redirect the unwanted output into a file, then remove the file when we’re done.
But there is an easier way. Unix and Linux systems have a special device that isn’t real hardware at all, just a bit bucket where we can dump unwanted data.
It’s called /dev/null and is perfect for these situations. Any data written there is simply thrown away, so it takes up no disk space.
Redirection makes it easy. In the first example, only the output going to standard error is thrown away.
In the second example, both standard output and standard error are discarded.
In rare cases, you may find yourself in a situation where /dev is on a read-only file system (for example, certain information security appliances), in which case you are stuck with the first suggestion of writing to a file and then removing it.