The /dev/null Linux and Unix “worm hole”

The /dev/null is a character file. I like to compare the /dev/null file with a worm hole, because it eats data.

$ file /dev/null
/dev/null: character special

The data redirected to the /dev/null is discarded by the system.

When debugging shell scripts, a good practice is to redirect the standard output to /dev/null, to avoid the error statement and look only at the error.

Next I will show you how to redirect to /dev/null. Also, read this article if you are interested in output redirection.

Redirect the standard output to /dev/null:

$ ./script > /dev/null

Redirect the standard error to /dev/null:

$ ./script 2> /dev/null

Redirect both standard output and standard error to /dev/null:

$ ./script &> /dev/null
OR:
$ ./script > /dev/null 2>&1

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!