Throwing Output Away
Problem
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.
Solution
Redirect the output to /dev/null as shown in these examples:
$ find / -name myfile -print 2> /dev/null
or:
$ noisy >/dev/null 2>&1
Discussion
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.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access