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

后端 未结 4 1476
Happy的楠姐
Happy的楠姐 2021-01-04 18:45

I have read this question: How to create a file with a given size in Linux?

But I havent got answer to my question.

I want to create a file of 372.07 MB,

4条回答
  •  温柔的废话
    2021-01-04 19:43

    Change your parameters:

    dd if=/dev/zero of=output.dat bs=1 count=390143672
    

    otherwise dd tries to create a 370MB buffer in memory.

    If you want to do it more efficiently, write the 372MB part first with large-ish blocks (say 1M), then write the tail part with 1 byte blocks by using the seek option to go to the end of the file first.

    Ex:

    dd if=/dev/zero of=./output.dat bs=1M count=1
    dd if=/dev/zero of=./output.dat seek=1M bs=1 count=42
    

提交回复
热议问题