Create a large file Quickly on Linux servers.

How can I quickly create a large file on a Linux system?

Normally dd command creates a large file but it reads from /dev/zeor and then writes to drive which can take a longer time which you need a very large file.
If you don’t care what should be the contents and just want to add the file quickly you can use fallocate command to do this.

Below command will create 10GB of file in no time. You can modify it as per your needs

# fallocate -l 10GB /justgeek
[[email protected] /]# du -sh justgeek
9.4G    justgeek
[[email protected] /]#

There are other options you can use for fallocate, you can try help command to explore more.

[[email protected] /]# fallocate --help

Usage:
 fallocate [options] <filename>

Preallocate space to, or deallocate space from a file.

Options:
 -c, --collapse-range remove a range from the file
 -d, --dig-holes      detect zeroes and replace with holes
 -i, --insert-range   insert a hole at range, shifting existing data
 -l, --length <num>   length for range operations, in bytes
 -n, --keep-size      maintain the apparent size of the file
 -o, --offset <num>   offset for range operations, in bytes
 -p, --punch-hole     replace a range with a hole (implies -n)
 -z, --zero-range     zero and ensure allocation of a range
 -x, --posix          use posix_fallocate(3) instead of fallocate(2)
 -v, --verbose        verbose mode

 -h, --help           display this help
 -V, --version        display version

For more details see fallocate(1).
[[email protected] /]#

Leave a Reply

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