There 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:
- Good old dd (slower option as it fills up the file)
$ dd if=/dev/zero of=out.img bs=1G count=1
- Sparse file of size 5GB using dd. No data, only file metadata is updated.
$ dd of=out.img bs=1M seek=5120 count=0
- Create a 1GB file instantly (and use up disk space too)
$ fallocate -l 1G out.img
- Sparse file using truncate
$ truncate -s 1G out.img
The reverse operation is to clear a file instantly:
- Just a redirection!
$ >out.img //This is also useful if you want to delete a huge file on Linux, clear and then use rm.
- truncate the file
$ truncate out.img