Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 See this if you're having trouble printing code examples


Unix Power Tools
What Can You Do with an Empty File?

by Jerry Peek
01/27/2000

It isn't a file, actually, though you can use it like one. /dev/null is a UNIX device. (Well, okay. It's a device file.) 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?

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 will give you a stop!):

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

On some UNIX versions, the head program may not terminate after it's printed the first ten lines. In that case, use sed 10q instead of head.


Back More Unix Power Tools

 

Copyright © 2009 O'Reilly Media, Inc.