/dev/zero

From Vero - Wikipedia
Jump to navigation Jump to search

Template:Confuse Template:Short description Template:Use dmy dates Template:Mono is a special file in Unix-like operating systems that provides as many null characters (ASCII NUL, 0x00) as are read from it.<ref>Template:Citation</ref> One of the typical uses is to provide a character stream for initializing data storage.<ref>Template:Citation</ref>

Function

Read operations from Template:Mono return as many null characters (0x00) as requested in the read operation.

Unlike Template:Mono, Template:Mono may be used as a source, not only as a sink for data. All write operations to Template:Mono succeed with no other effects. However, Template:Mono is more commonly used for this purpose.

When Template:Mono 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.

History

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

Examples

Erasing a file system partition or drive:

cp /dev/zero /dev/<destination drive or partition>

(Note that this does not perform a secure erasure, may not destroy the data at all, and may take significantly more time than required – for this purpose, domain-specific tooling like blkdiscard may be preferred for devices that support TRIM.)

Creating a Template:Val file, called foobar, filled with null characters:

Template:Sxhl

Instead of creating a file really filled with only zero bytes, many file systems also support the creation of sparse files, which return zeros upon reading but use less actual space. The classic way of doing this (without the domain-specific truncate utility) would be, to create a Template:Val file:

dd Template:Abbr=1 Template:Codett

which seeks to position seekTemplate:Timesbs = Template:Nowrap in the output and copies countTemplate:Timesbs = 1 byte from /dev/zero, thus making the file contain only one data block.

See also

References

Template:Reflist