Jump to content

/dev/zero: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Tags: references removed Mobile edit Mobile web edit adding email address
No edit summary
Line 1: Line 1:
blackhole-100012023170380-1509852443@[[Blackhole-100012023170380-1509852443@devnull.facebook.com|devnull.facebook.com]]{{short description|Special file in Unix-like operating systems}}
<br />

==Function==
==Function==
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.

Revision as of 11:55, 23 January 2020

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

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

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 null characters:[5]

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=1GB

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.[6]

See also

References

  1. ^ ""C" run-time program bootstrap from SunOS, contributed to CSRG for inclusion in 4.4BSD". TUHS.
  2. ^ "HP-UX 8.0.7 install media".
  3. ^ Beal, Chris. "So what the heck is anonymous memory". Oracle Blog.
  4. ^ "MAP_ANON description in mmap(2)". NetBSD.
  5. ^ Optimizing NFS Performance: Tuning and Troubleshooting NFS on HP-UX Systems, Dave (2002). Olker. Prentice Hall Professional. pp. 26–7. ISBN 9780130428165. Retrieved 16 July 2014.
  6. ^ Sparse file