How can I quickly make a large file?
The zero-fill method (here modified to avoid potential memory bottlenecks) took 17 seconds to create a 10 GB file on an SSD and caused Ubuntu's graphical interface to become unresponsive.
$ time sh -c 'dd if=/dev/zero iflag=count_bytes count=10G bs=1M of=large; sync'
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 17.2003 s, 624 MB/s
real 0m17.642s
user 0m0.008s
sys 0m9.404s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
10737422336 large
fallocate creates large files instantly by directly manipulating the file's allocated disk space:
$ time sh -c 'fallocate -l 10G large; sync'
real 0m0.038s
user 0m0.000s
sys 0m0.016s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
10737422336 large
truncate also works instantly, and creates sparse files which don't use up actual disk space until data is written later on:
$ time sh -c 'truncate -s 10G large; sync'
real 0m0.014s
user 0m0.000s
sys 0m0.004s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
0 large
An easy way would be to use the dd
command to write a file full of zeros.
dd if=/dev/zero of=outputFile bs=2G count=1
- if = input file
- of = output file
- bs = bytes
Use G in the size argument if you want computer (1024*1024*1024) gigabytes, or GB if you want human (1000*1000*1000) gigabytes.