How To Create Files Of A Certain Size In Linux

Create Files Of A Certain Size In Linux

6 Responses

  1. Luc Van Rompaey says:

    Just a sidenote: With the bash shell, you can do inline arithmetic, so you won’t have to calculate how many bytes go into 5 MiB beforehand.
    Just do:
    fallocate -l $(( 5 * 1024 * 1024 )) ostechnix.txt

  2. AshkanV says:

    I think its good to mention that the first 2 command only allocate file with the given size in the file system, which is means no IO overhead.
    but the other two create an empty file and extending it by writing data in it, which means LOTS of IO overhead

    By the way thanks for good and useful article.

  3. Claudio Dobniewski says:

    Thanks, is very useful info

  4. Gergely Polonkai says:

    It also worth noting that truncate creates a file that looks like that size, but doesn’t allocate space. If you want to create a fake block device or a swap file you can’t use it, as the kernel will tell you “it has holes”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.