[Linux] Special files/dev/zero

Source: Internet
Author: User

/dev/zero is a special file in a Unix-like system that provides an infinite null character when the file is read. One of its main uses is to provide a character stream to initialize the data store, which is to overwrite the target data with a null character. Another common use is to produce a blank file of a specific size.

You can read a null character of any size from/dev/zero. Unlike/dev/null,/dev/zero not only serves as a data black hole, but also serves as a source of data. You can write data to the/dev/zero file, but it doesn't actually have any effect. But in general we still use/dev/null to do this thing.

When using Mmap to map/dev/zero memory to a virtual address space, this is equivalent to using anonymous memory, which means that memory is not associated to any file.

Example

The Unix command DD reads a eight-byte stream from the source file to the destination file, which may also involve data conversion. To destroy data on a file system partition:

DD if=/dev/zero of=/dev/<destination partition>

Now we create a 1M file Foobar, whose contents are empty:

DD if=/dev/zero of=foobar count=1024x768 bs=1024x768

Note: The block size can be specified directly using numeric units, such as GB, MB, and so on. To create a 1GB file, you can do this:

DD if=/dev/zero of=foobar count=1 bs=1g

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.