How to create a file with a given size in Linux?

后端 未结 13 1090
既然无缘
既然无缘 2020-11-28 17:57

For testing purposes I have to generate a file of a certain size (to test an upload limit).

What is a command to create a file of a certain size on Linux?

相关标签:
13条回答
  • 2020-11-28 18:42

    There are lots of answers, but none explained nicely what else can be done. Looking into man pages for dd, it is possible to better specify the size of a file.

    This is going to create /tmp/zero_big_data_file.bin filled with zeros, that has size of 20 megabytes :

        dd if=/dev/zero of=/tmp/zero_big_data_file.bin  bs=1M count=20
    

    This is going to create /tmp/zero_1000bytes_data_file.bin filled with zeros, that has size of 1000 bytes :

        dd if=/dev/zero of=/tmp/zero_1000bytes_data_file.bin  bs=1kB count=1
    

    or

        dd if=/dev/zero of=/tmp/zero_1000bytes_data_file.bin  bs=1000 count=1
    

    • In all examples, bs is block size, and count is number of blocks
    • BLOCKS and BYTES may be followed by the following multiplicative suffixes: c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.
    0 讨论(0)
提交回复
热议问题