A good place to go when you need hex 000000000. And it's catholic in its embrace of numbering systems. It will happily spew octal and binary too. You can get the ASCII version with "$ yes 0"

Unlike /dev/null which is relatively well understood as to how and why it behaves so, /dev/zero has remained an enigma for many. Who would want and endless stream of nothing?

While cat /dev/null > file creates an empty file of zero length, cat /dev/zero > file creates a file filled with nothing but with some length (and if you don't kill it, this will fill up the disk with nothing). There are many times you want an empty file of some length, and for this /dev/zero is coupled with dd. One example of this can be found in the Linux man page 'mkswap(8)'

To setup a swap file, it is necessary to create that file before running mkswap, e.g. using a command like
# dd if=/dev/zero of=swapfile bs=1024 count=65536
Note that a swap file must not contain any holes (so, using cp(1) to create the file is not acceptable).
This will create a 64 megabyte file named swapfile filled with zeros. Other systems (such as Solaris) have a program that creates files and hides /dev/zero from you. The Solaris version is called 'mkfile', however looking at the man page you can still see /dev/zero's fingerprints:
mkfile creates one or more files that are suitable for use as NFS-mounted swap areas, or as local swap areas. When a root user executes mkfile(), the sticky bit is set and the file is padded with zeros by default. When non-root users execute mkfile(), they must manually set the sticky bit using chmod(1). The default size is in bytes, but it can be flagged as kilobytes, blocks, or megabytes, with the k, b, or m suffixes, respectively.

A "quick" (but hardly secure) way of emptying a disk of its contents is to cat /dev/zero > /dev/hda or dd if=/dev/zero of=/dev/hda. This will, from the first block to the last fill the entire disk with zeros. This is a good way to get a Microsoft product off of a disk and boot blocks to make certain that it is clean for making a new file system upon. As mentioned, this is not secure and advanced disk recovery systems can read erased bytes. The military often requires disks to be scrubbed several types though as technology has gone further even this has proven unsuitable for secure erasing of disks. Many military sites will send back a lump of metal with the serial number plate on it for RMAs realizing that the only the permanent physical destruction of the storage media is the safe way to erase the data upon it.

Log in or registerto write something here or to contact authors.