Reference articles on history, science, culture and more
Encyclopedia

/dev/zero

Special file in Unix-like operating systems

/dev/zero is a special file in Unix-like operating systems that provides as many null characters (ASCII NUL, 0x00) as are read from it. One of the typical uses is to provide a character stream for initializing data storage.

01Function

Read operations from /dev/zero return as many null characters (0x00) as requested in the read operation.

All write operations to /dev/zero succeed with no other effects. /dev/null is more commonly used for this purpose.

When /dev/zero is memory-mapped, e.g., with mmap, to the virtual address space, it is equivalent to using anonymous memory; i.e. memory not connected to any file.

02History

/dev/zero was introduced in 1988 in SunOS-4.0 to allow a mappable BSS segment for shared libraries using anonymous memory. HP-UX 8.x introduced the MAP_ANONYMOUS flag for mmap(), which maps anonymous memory directly without a need to open /dev/zero. Since the late 1990s, MAP_ANONYMOUS or MAP_ANON are supported by most UNIX versions, removing the original purpose of /dev/zero.

03Examples

Erasing a USB flash drive using DD:

dd if=/dev/zero of=/dev/<destination drive>

This may not perform a secure erasure and may not destroy any data, but may take significantly more time than required for this purpose.

Creating a 1 MiB file, named foobar, filled with null characters:

head -c $((1024 * 1024)) /dev/zero >foobar
Watch videos about /dev/zeroExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article /dev/zero, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.