Glossary

/dev/zero

/dev/zero is a character device that returns an endless stream of null (0x00) bytes when read. Writes to it are discarded like /dev/null. Its primary use is creating zero-filled files or blocks of memory, for testing, benchmarking, or setting up disk images.

dd if=/dev/zero of=empty.img bs=1M count=1024   # 1 GB zeroed file
dd if=/dev/zero of=/dev/sdb bs=1M               # zero a whole disk

On modern filesystems with sparse file support, you can create a zero-filled file that consumes no disk space until written to:

truncate -s 10G sparse.img          # logical 10 GB, physical 0
dd if=/dev/zero of=dense.img bs=1M count=10240   # actual 10 GB

/dev/zero is also used by mmap with MAP_ANONYMOUS to obtain a zeroed region of memory, though programs usually call mmap directly rather than going through the file. Along with /dev/null and /dev/urandom, it is one of the three most used virtual devices in Linux scripting.

Related terms: /dev, Device File, /dev/null

Also defined in: Textbook of Linux