What Can You Do with an Empty File?

It isn't a file, actually, though you can use it like one. /dev/null is a Unix device.[6] It's not a physical device. /dev/null 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?

% progname 
               > /dev/null &
% grep "
               outputfile
               " * /dev/null

Another interesting device (mostly for programmers) is /dev/zero. When you read it, you'll get ASCII zeros (NUL characters) forever. 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 head (Section 12.12) will give you a stop!):[7]

od Section 12.4

% fold -20 /dev/zero | od -c | head

— JP



[6] Well, okay. It's a device file.

[7] On some Unix versions, the head program may not terminate after it has printed the first 10 lines. In that case, use sed 10q instead of head.