Linux users run into scenarios where large files are needed for testing. Fortunately, Linux is already equipped with tools & commands needed for this purpose.
Using fallocate command
Linux distros come with the fallocate command.
Here is an example of creating a 5GB file in a second. This is the fastest way to create large files. Faster than the dd command.
$ fallocate -l 5G example
Using the dd command
“dd” command can also be used to create large files quickly.
You need to pass the buffer size and count. The file size created is [buffer size ] * [count]
The example below creates a 10GB file and it is very fast as it puts all zeros.
$dd if=/dev/zero of=sample1.dummy count=1 bs=1 seek=$((10 * 1024 * 1024 * 1024 -1))
The example below creates a 10GB file with random content (using buffer size of 1mb).
$dd if=/dev/urandom of=sample2.dummy bs=1M count=10240
The example below creates a 10GB file with random content (using buffer size of 10mb).
$dd if=/dev/urandom of=sample3.dummy bs=10M count=1024