UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 13.13 The "Filename" - Chapter 13
Redirecting Input and Output
Next: 13.15 What to Do with a Full Bit Bucket :-)
 

13.14 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. [4] 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?

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

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

[5] 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.

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

- JP


Previous: 13.13 The "Filename" - UNIX Power ToolsNext: 13.15 What to Do with a Full Bit Bucket :-)
13.13 The "Filename" - Book Index13.15 What to Do with a Full Bit Bucket :-)

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System