Null device

/ dev / null ( zero english: "nothing" dt ) is the name of a specific virtual device file, the null device on Unix and Unix -like operating systems, which discards any data that is written there. Under CP / M and its derivatives DOS, OS / 2 and Microsoft Windows, the zero device as NUL: addressed. Under DOS and successor operating systems, the zero device exists in each directory under the filename NUL. The file / dev / null is standardized by the POSIX standard.

Use

A common use is for example, / null redirect the messages of a program 's standard output, instead of the screen to / dev in a shell session, if one is not interested in them; they are not displayed. The device / dev / null can also serve as a destination for file system operations. Such an objective occurs occasionally when shell scripts or programs require necessarily a file specification, but this does not make sense in this case or is undesirable.

Read accesses deliver an immediate end of file ( end of file, "EOF "). In this case, the device behaves like an ordinary file, the program must be open so take any special precautions.

In the network culture is / dev / zero is a commonly used term for a kind of gedankliches black hole, usually to express lack of interest on the statement of the interlocutor.

Examples

If you want to see only the normal output of a program, but not the error messages and other information that the program writes to standard error output, you can redirect this:

$ Program 2 > / dev / null If you want to use for shell scripts only the return value of a program and thus divert all expenses to / dev / null, the following syntax can be used:

$ Program > / dev / null 2 ​​> & 1 Using Shell Pipes can selectively hide uninteresting ( error) messages from parts of the pipeline:

$ Scheme1 2 > / dev / null | programme2 | ... Similarly, the use of means of symbolic link, then, anything in the linked file (~ / bash_history. ) Is written, not stored, for example, for data protection:

$ Ln -sf / dev / null ~ /. Bash_history Also common is the use of standard input. An example of this is to run a command in the background during an SSH session. The standard input is null is passed to / dev /, so the program continues to run in the background even when you log out of the SSH session:

$ Ssh example.com " program / dev / null 2 ​​> & 1 &" You can also check a disk by copying for example, / dev/cdrom0 to / dev / null. Here, if an error occurs, the corresponding disk is corrupt or missing.

$ Dd if = / dev / cdrom of = / dev / null see also

  • Ln ( Unix) | ssh | dd ( Unix)
  • Output device
  • Write- only memory
  • POSIX
233804
de