/dev/null And /dev/zero On Linux And Unix: What's The Difference?
Apr 29, 2009, 20:02 (0 Talkback[s])
(Other stories by Mike Tremell)
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
[ Thanks to Mike
Golvach for this link. ]
"2. Reading from /dev/null and /dev/zero: This is where
the difference between the two files becomes apparent. The most
significant difference is exposed in the "reading" since this
action highlights the major way in which the two differ.
"/dev/null is, essentially, a black hole. Writes to it (as noted
above), basically go down the drain. They go nowhere, stay there
and you can't get them back. When you "read" from /dev/null, the
same rule holds true. /dev/null is virtually "nothing," and all
reads from it produce no output whatsoever. For instance, this
output from Solaris' truss (you can get the same from Linux's
"strace" and similar utilities) shows what happens when /dev/null
is read from (e.g. "cat /dev/null") - below, what you'd see at the
command line, followed by a snippet of truss output from the
almost-immediate end of the command's execution:"