Unix Power ToolsUnix Power ToolsSearch this book

43.12. 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.[132] 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?

[132]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) 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!):[133]

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

od Section 12.4

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

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.