Patricio Treviño

Patricio Treviño

Husband . Father . Developer

Redirecting streams to the /dev/null sink

Redirects the stdout/stderr (or both) to a special location called /dev/null.

The /dev/null device is a special file (not a directory) and it's typically used as a sink for unwanted output streams of a process, or as a convenient empty file for input streams. This is usually done by redirection.

Why is this important? Well imagine you have a very important process that cannot not be interrupted, redirecting outputs is a good way to avoid unhandled errors.


<operation> [n]> /dev/null [options]
view raw syntax.text hosted with ❤ by GitHub

Option Description
operation The operation whose output will be redirected.
n The stream to be redirected (see below).
options The stream redirection options.

Valid values for [n]: 1, standard out 2, standard error &, both


# no redirection
$ echo 'hello'
# redirects standard error (no error in this case)
$ echo 'hello' 2> /dev/null
# redirects standard out to /dev/null (so no output)
$ echo 'hello' 1> /dev/null
# redirects everything to /dev/null (so no output)
$ echo 'hello' &> /dev/null
# no redirection (causing error)
$ unlink
unlink: No such file or directory
# redirects standard error to /dev/null (so no error)
$ unlink 2> /dev/null
# redirects everything to /dev/null (so no error)
$ unlink &> /dev/null
view raw hosted with ❤ by GitHub


Null device