Redirecting Input and Output
It isn't a file, actually, though you can use it like one.
is a UNIX device.
It's not a physical device.
is a special device that "eats" any text written to it
and returns "end-of-file" (a file of length 0) when you read from it.
So what the heck can you use it for?
Empty another file.
Just copy /dev/null
"on top of" the other file . (24.1
Make another program "quiet" by redirecting its output there.
For instance, if you're putting a program into the background
and you don't want it to bother you, type:
> /dev/null &
standard output but leaves standard error hooked to your
terminal, in case there is an error.
Answer a program that asks a lot of questions-you know you'll just press
at each prompt.
In a lot of cases, you can redirect the program's standard input from
Want the default setup? If yes, press RETURN:
Enter filename or press RETURN for default:
You should test that with each program, though, before you assume this trick
(If it doesn't work, try
Where a program needs an extra filename but you don't want it to read or
write an actual file.
For instance, the
programs won't give the name of the file where they find a match unless there
are at least two filenames on the command line.
When you use a wildcard in a directory where maybe only one file will match,
to be sure that grep
will always see more than one : (17.20
" * /dev/null
You're guaranteed that grep
won't match its regular expression in
shows even more uses for /dev/null
Another interesting device (mostly for programmers) is /dev/zero
When you read it, you'll get
ASCII zeros (NUL characters) (51.3
There are no newlines either.
For both of those reasons, many UNIX commands have trouble reading it.
If you want to play, the command below will give you a start (and
will give you a stop!):
fold -20 /dev/zero | od -c | head