Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought


 null(F)                       06 January 1993                        null(F)


 Name

    null - data sink or empty source

 Description

    The null special file /dev/null can always be opened, read from, or writ-
    ten to.

    Data written to the null special file is discarded.

    No data can be read from null since an immediate end-of-file (EOF)
    occurs; a read(S) system call on null will always return 0 (zero).

 Examples

    Unwanted output can be discarded by redirecting the standard output or
    standard error to /dev/null. The following example shows only those files
    which are missing from a directory by using ls(C) and discarding anything
    on standard output:

       ls file1 file2 ...  > /dev/null

    Sometimes you might not want to see the error messages from a command.
    If you are looking for a file in a filesystem using the find(C) command,
    you can ignore the messages (on standard error) telling you that you did
    not have permission to look at certain directories:

       find / -name  foofile  -print  2>  /dev/null

    You can also use null to obtain harmless input. In the following example,
    grep(C) is forced to output the name of each file containing pattern as
    well as the matching lines:

       find / -exec grep pattern  {}  /dev/null \;

    find runs grep on every file in the entire filesystem in turn. If
    /dev/null was not given as an additional file to search, grep would print
    the matching lines found, but not the name of the file. This is because
    grep omits the filename when examining only one file. /dev/null acts as a
    ``dummy'' second file.

    A more common use of null as input is to discard the contents of a file
    but leave its entry in the directory:

       cat  /dev/null  >  file_to_empty

    An alternative way of doing this is to copy null to the file:

       cp  /dev/null  file_to_empty


 Notes

    /dev/null is implemented using the mm character special driver, and
    always has a minor device number of 0 (zero). The mm driver and /dev/null
    must be present for the correct operation of SCO UNIX System V.

 Standards conformance

    null is conformant with:

    AT&T SVID Issue 2;
    and X/Open Portability Guide, Issue 3, 1989.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026