Generate a file of the specified size in Linux

Source: Internet
Author: User
Article Title: generate a file of the specified size in Linux. Linux is a technology channel of the IT lab in China. It includes desktop applications, Linux system management, kernel research, embedded systems, open-source systems, and other basic categories in the installation system. Therefore, remember something here.
 
When discussing the NVR project with the manager, he mentioned that it is easier to reserve the disk space specified by the user in advance. What is not easy to implement is to write a file system by yourself. I am not sure about this method. If you are interested, you can go to SourceForge to find an open-source project to learn, to be honest, I cannot understand it. With the help of Li sumei, I did an experiment on reserved disk space, which is essentially like this:
 
(1) first, use the dd command on the partition to reserve space to generate a file of the specified size:
 
# Create a 10 M file named foobar:
 
# Dd if =/dev/zero of =/home/foobar bs = 1 K count = 10000
 
/Dev/zero
 
From Wikipedia, the free encyclopedia
 
In Unix-like operating systems,/dev/zero is a special file that provides as contains null characters (ascii null, 0x00; not ASCII character "digit zero ", "0", 0x30) as are read from it. one of the typical uses is to provide a character stream for overwriting information. another might be to generate a clean file of a certain size. using mmap to map/dev/zero to RAM is the BSD way of implementing shared memory.
 
(2) format the file:
 
# Mke2fs-vFm0/home/foobar 100000000 // (1 K * 10000)
 
(3) mount the file and then write content to the file, just like writing content to a directory:
 
# Mount-o loop home/foobar/mnt/mountpoint
 
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.