Create huge files on Linux instantly

tux_compThere are those times during development when you may need to fill up a partition quickly to do some stress testing or measure network speed etc. Instead of looking for big files (even in TBs or beyond) you can use some cute utilities on Linux to do this. You will also be able to control the exact size of the file. Here are 3 ways to do this easily:

  1. Good old dd (slower option as it fills up the file)
    $ dd if=/dev/zero of=out.img bs=1G count=1
  2. Sparse file of size 5GB using dd. No data, only file metadata is updated.
    $ dd of=out.img bs=1M seek=5120 count=0
  3. Create a 1GB file instantly (and use up disk space too)
    $ fallocate -l 1G out.img
  4. Sparse file using truncate
    $ truncate -s 1G out.img

The reverse operation is to clear a file instantly:

  1. Just a redirection!
    $ >out.img
    //This is also useful if you want to delete a huge file on Linux, clear and then use rm.
  2. truncate the file
    $ truncate out.img

One thought on “Create huge files on Linux instantly”

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s