Null device

from Wikipedia, the free encyclopedia

As null device , English null device , in computing is a virtual output device referred that everything that is written on it discards. As a device file , it is therefore also the implementation of the null value at the file system level.


Almost all operating systems have a virtual device file for the null device. Although the names are different, the function is basically the same.

Designations for the null device:


Redirection of the data streams

The null device is always used when an output appears to be processed, but is actually to be discarded without indicating an error on the output device. Especially in batch processing , such as BAT files under PC-compatible DOS or under Windows or shell scripts under Unix, the null device is often used to suppress the output of commands. This is achieved by redirecting the standard data streams .

Example of application under PC-compatible DOS such as MS-DOS :

path c:\dos >nul

If the directory C:\DOS exists, it will be included in the search path . If it does not exist, however, an (unsightly and unprofessional looking) error message would be displayed on the screen , but this is now NUL:diverted to the null device and is therefore no longer displayed.

Example with bash , e.g. B. under Linux :

cat /proc/uptime 1> /tmp/uptime.txt 2>/dev/null

Executes the command cat /proc/uptimeand writes the output to the file stdoutvia . Error messages to, however, are redirected to the null device via and are neither displayed on the screen nor written to the file . 1>/tmp/uptime.txtstderr2>/tmp/uptime.txt

Use at the file system level

Not only Unix-like systems , the device can zero (the Unix motto according Everything is a file is a regular file can be used as):

cp /dev/null leer.txt

This input creates an empty file leer.txtby copying the null device like a file. The output from /dev/nullis always End of File , so the newly copied file is leer.txtempty. The same works u. a. also under MS-DOS:

copy nul leer.txt

Individual evidence

  1. DevynCJohnson: Overview of / dev / null. July 19, 2015, accessed on July 11, 2018 (English): "FUN FACT: / dev / null is equivalent to the" NULL "file call used by Windows (\ Device \ Null), OpenVMS (NL:), Amiga ( NIL:), and DOS and CP / M (NUL: or NUL). "
  2. Adi Oltean: Tricks around the “copy” command… ( blog ) In: Adi Oltean's weblog. Microsoft Developer Network , February 25, 2005, accessed July 11, 2018 .