411 REFERENCE · Wikipedia
/dev/zero
Reference material by Wikipedia contributors. This retains its source identity and is not 411 news reporting.
Null device
Special file in Unix-like operating systems
February 2020 y
/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.Advanced Linux Programming Mark Mitchell Jeffrey Oldham Alex Samuel Sams Publishing 2001 9780735710436 https://books.google.com/books?id=oRqqAVyXjwAC&pg=PA136 6.5.2 /dev/zero 136 One of the typical uses is to provide a character stream for initializing data storage.Linux System Programming: Talking Directly to the Kernel and C Library Robert Love O'Reilly Media, Inc. 2007 9780596009588 https://books.google.com/books?id=k_ocKY0iegsC&pg=PA259 Mapping /dev/zero 259–260
Function
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.
History
/dev/zero was introduced in 1988 in SunOS-4.0 to allow a mappable BSS segment for shared libraries using anonymous memory."C" run-time program bootstrap from SunOS, contributed to CSRG for inclusion in 4.4BSD https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/src/contrib/sun.sharedlib/lib/csu/m68k/crt0.s TUHS HP-UX 8.x introduced the MAP_ANONYMOUS flag for mmap(), which maps anonymous memory directly without a need to open /dev/zero.HP-UX 8.0.7 install media 22 July 1992 https://archive.org/details/hp-ux8.07forhp9000s7xx Since the late 1990s, MAP_ANONYMOUSBeal Chris So what the heck is anonymous memory https://blogs.oracle.com/cwb/so-what-the-heck-is-anonymous-memory Oracle Blog 2019-09-09 2021-04-15 https://web.archive.org/web/20210415103111/https://blogs.oracle.com/cwb/so-what-the-heck-is-anonymous-memory dead or MAP_ANON are supported by most UNIX versions, removing the original purpose of /dev/zero.MAP_ANON description in mmap(2) https://netbsd.gw.com/cgi-bin/man-cgi?mmap NetBSD 2019-09-09 2019-11-25 https://web.archive.org/web/20191125152633/https://netbsd.gw.com/cgi-bin/man-cgi?mmap dead
Examples
January 2026
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.January 2026
Creating a 1 MiB file, named foobar, filled with null characters:
bash head -c $((1024 * 1024)) /dev/zero >foobar
See also
Unix philosophy
Standard streams
:/dev
:/dev/full
References
Category:Unix file system technology
Category:Device file