/dev/zero: Difference between revisions
imported>Nabijaczleweli |
imported>Kbrose clean out advice |
||
| Line 7: | Line 7: | ||
Read operations from {{mono|/dev/zero}} return as many [[null character]]s (0x00) as requested in the read operation. | Read operations from {{mono|/dev/zero}} return as many [[null character]]s (0x00) as requested in the read operation. | ||
All write operations to {{mono|/dev/zero}} succeed with no other effects. However, {{mono|/dev/null}} is more commonly used for this purpose. | |||
When {{mono|/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. | When {{mono|/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== | ==History== | ||
{{mono|/dev/zero}} was introduced in 1988 | {{mono|/dev/zero}} was introduced in 1988 in SunOS-4.0 to allow a mappable BSS segment for shared libraries using anonymous memory.<ref>{{cite web |title="C" run-time program bootstrap from SunOS, contributed to CSRG for inclusion in 4.4BSD |url=https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/src/contrib/sun.sharedlib/lib/csu/m68k/crt0.s |website=TUHS}}</ref> HP-UX 8.x introduced the MAP_ANONYMOUS flag for mmap(), which maps anonymous memory directly without a need to open {{mono|/dev/zero}}.<ref>{{cite web |title=HP-UX 8.0.7 install media |date=22 July 1992 |url=https://archive.org/details/hp-ux8.07forhp9000s7xx}}</ref> Since the late 1990s, MAP_ANONYMOUS<ref>{{cite web |last1=Beal |first1=Chris |title=So what the heck is anonymous memory |url=https://blogs.oracle.com/cwb/so-what-the-heck-is-anonymous-memory |website=Oracle Blog |access-date=2019-09-09 |archive-date=2021-04-15 |archive-url=https://web.archive.org/web/20210415103111/https://blogs.oracle.com/cwb/so-what-the-heck-is-anonymous-memory |url-status=dead }}</ref> or MAP_ANON are supported by most UNIX versions, removing the original purpose of {{mono|/dev/zero}}.<ref>{{cite web |title=MAP_ANON description in mmap(2) |url=https://netbsd.gw.com/cgi-bin/man-cgi?mmap |website=NetBSD |access-date=2019-09-09 |archive-date=2019-11-25 |archive-url=https://web.archive.org/web/20191125152633/https://netbsd.gw.com/cgi-bin/man-cgi?mmap |url-status=dead }}</ref> | ||
==Examples== | ==Examples== | ||
[[Data erasure|Erasing]] a file system partition or drive: | [[Data erasure|Erasing]] a file system partition or drive: | ||
cp /dev/zero /dev/<destination drive or partition> | cp /dev/zero /dev/<destination drive or partition> | ||
However, this may not perform a secure erasure, may not destroy the data at all, and may take significantly more time than required–for this purpose. | |||
Creating a {{val|1|ul=MiB}} file, called ''[[foobar]]'', filled with null characters: | |||
{{sxhl|2=bash|head -c $(( 1024 * 1024 )) /dev/zero >foobar}} | |||
==See also== | ==See also== | ||
Latest revision as of 16:10, 29 December 2025
Script error: No such module "Distinguish". Template:Short description Template:Use dmy dates <templatestyles src="Mono/styles.css" />/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]
Function
Read operations from <templatestyles src="Mono/styles.css" />/dev/zero return as many null characters (0x00) as requested in the read operation.
All write operations to <templatestyles src="Mono/styles.css" />/dev/zero succeed with no other effects. However, <templatestyles src="Mono/styles.css" />/dev/null is more commonly used for this purpose.
When <templatestyles src="Mono/styles.css" />/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
<templatestyles src="Mono/styles.css" />/dev/zero was introduced in 1988 in SunOS-4.0 to allow a mappable BSS segment for shared libraries using anonymous memory.[3] HP-UX 8.x introduced the MAP_ANONYMOUS flag for mmap(), which maps anonymous memory directly without a need to open <templatestyles src="Mono/styles.css" />/dev/zero.[4] Since the late 1990s, MAP_ANONYMOUS[5] or MAP_ANON are supported by most UNIX versions, removing the original purpose of <templatestyles src="Mono/styles.css" />/dev/zero.[6]
Examples
Erasing a file system partition or drive:
cp /dev/zero /dev/<destination drive or partition>
However, this may not perform a secure erasure, may not destroy the data at all, and may take significantly more time than required–for this purpose.
Creating a Script error: No such module "val". file, called foobar, filled with null characters:
See also
- Unix philosophy
- Standard streams
- <templatestyles src="Mono/styles.css" />/dev
- <templatestyles src="Mono/styles.css" />/dev/null
- <templatestyles src="Mono/styles.css" />/dev/full
References
<templatestyles src="Reflist/styles.css" />
Script error: No such module "Check for unknown parameters".