Differences between input stream from /dev/null and /dev/zero?


Recommended Posts

I know that I can create a file (1 GB) with following command:

dd if=/dev/zero of=EmptyFile bs=100M count=10

But I wonder what are the differences if I execute the following command:

dd if=/dev/null of=EmptyFile bs=100M count=10

Let me guess... The one with input from /dev/zero is full of zero (0) and the one with input from /dev/null is full of nothing (null!)?

BTW, Last time I tried to less the file which was created with first command (input from /dev/zero), but nothing could be read, why? I expected full screen of 0.

Thanks.

/dev/zero returns the null character (0x00), while /dev/null returns an eof. The former can be user to fill your file (although it will appear empty if you cat it) while the latter will always give a 0 length file.

The point of /dev/null is usually to work as sink for output streams meant to be discarded, not as an input stream (you'd get the same doing "touch filename", and it's shorter).

Edited by ichi
  ichi said:
/dev/zero returns the null character (0x00), while /dev/null returns an eof. The former can be user to fill your file (although it will appear empty if you cat it) while the latter will always give a 0 length file.

The point of /dev/null is usually to work as sink for output streams meant to be discarded, not as an input stream (you'd get the same doing "touch filename", and it's shorter).

Oh thanks. :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.