/dev/zero is a special file in a Unix-like system that provides an infinite null character when the file is read. One of its main uses is to provide a character stream to initialize the data store, which is to overwrite the target data with a null character. Another common use is to produce a blank file of a specific size.
You can read a null character of any size from/dev/zero. Unlike/dev/null,/dev/zero not only serves as a data black hole, but also serves as a source of data. You can write data to the/dev/zero file, but it doesn't actually have any effect. But in general we still use/dev/null to do this thing.
When using Mmap to map/dev/zero memory to a virtual address space, this is equivalent to using anonymous memory, which means that memory is not associated to any file.
Example
The Unix command DD reads a eight-byte stream from the source file to the destination file, which may also involve data conversion. To destroy data on a file system partition:
DD if=/dev/zero of=/dev/<destination partition>
Now we create a 1M file Foobar, whose contents are empty:
DD if=/dev/zero of=foobar count=1024x768 bs=1024x768
Note: The block size can be specified directly using numeric units, such as GB, MB, and so on. To create a 1GB file, you can do this:
DD if=/dev/zero of=foobar count=1 bs=1g