null(F)


null -- data sink or empty source

Description

The null special file /dev/null can always be opened, read from, or written 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 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 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 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 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

Warning

/dev/null is implemented using the mm character special driver. The mm driver and /dev/null must be present for correct operation of the system.

See also

byte(F), find(C), grep(C), ls(C), read(S)

Standards conformance

null is conformant with:

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


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005