/dev/zero
Special device files |
---|
|
/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.[1] One of the typical uses is to provide a character stream for initializing data storage.[2]
Contents
Function
Read operations from /dev/zero return as many null characters (0x00) as requested in the read operation.
Unlike /dev/null, /dev/zero may be used as a source, not only as a sink for data. All write operations to /dev/zero succeed with no other effects. However, /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.
History
Lua error in package.lua at line 80: module 'strict' not found. /dev/zero was introduced in 1988 by SunOS-4.0 in order to allow a mappable BSS segment for shared libraries using anonymous memory.[citation needed] In the mid 1990s, HP-UX introduced the mmap() flag MAP_ANONYMOUS that maps anonymous memory directly without a need to open /dev/zero.[citation needed] Since the late 1990s, MAP_ANONYMOUS is supported by most UNIX versions, removing the original purpose of /dev/zero.[citation needed]
Examples
The dd Unix utility program reads octet streams from a source to a destination, possibly performing data conversions in the process. Destroying existing data on a file system partition (low-level formatting):
dd if=/dev/zero of=/dev/<destination partition>
Creating a 1 MiB file, called foobar, filled with zeroes:[3]
dd if=/dev/zero of=foobar count=1024 bs=1024
Note: The block size value can be given in SI (decimal) values, e.g. in GB, MB, etc. To create a 1 GB file one would simply type:
dd if=/dev/zero of=foobar count=1 bs=1G
Note: Instead of creating a real file with only zero bytes, many file systems also support the creation of sparse files which returns zeros upon reading but use less actual space.[4]
See also
References
<templatestyles src="Reflist/styles.css" />
Cite error: Invalid <references>
tag; parameter "group" is allowed only.
<references />
, or <references group="..." />
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Sparse file