/dev/null is a character special device file on Unix systems. Any information written to /dev/null is discarded by its driver; reading from /dev/null results in EOF.

/dev/null is often used in Unix shell programming; for example:

  • <tt>cp /dev/null somefile</tt>
creates an empty file or empties an existing file
  • <tt>some-command 2>/dev/null</tt>
discards the stderr output of some-command

/dev/null is not only used by users and scripts; oftentimes, it is used in C programs. For example, when a program daemonizes itself, it will likely close stdin, stdout and stderr and reopen them to /dev/null. This ensures that the program will not be blocked waiting for terminal I/O if it is disassociated from its terminal, nor will it send spurious messages to the system console if the programmer accidentally leaves in a printf statement. As another example, some setuid programs were recently found to have security vulnerabilities as they expected stdin, stdout and stderr to already be open at launch. Since file descriptors are allocated linearly, the next file the setuid program opens will use file descriptor 0, 1 or 2 and reading or writing from these files interferes with the program’s behaviour. Linux and *BSD addressed this issue with a kernel patch that examines the file descriptor table for setuid programs upon exec() and opens file descriptors 0, 1 or 2 to /dev/null if they are not already open.

The path <tt>/dev/null</tt> must point to the null special character file according to the Single Unix Specification ( This occasionally does not happen; for example, a chroot environment missing a /dev/null file is non-compliant. For maximum portability, programs should check for <tt><paths.h></tt> and then check for <tt>-PATH-DEVNULL</tt> and if unavailable, fall back to <tt>”/dev/null”</tt>.

The term has entered the day-to-day vocabulary of many Unix users; for example “Send that cease-and-desist letter to /dev/null!” or “I procmail all my spam to /dev/null.”

TakeDown.NET -> “Dev-Null