For my work and personal projects, I sometimes need to create large files greater than 100MB, sometimes 500MB and often 1GB, 5GB, 10GB up to 100GB.

There are many ways to create large files with random content, but we will focus on the dd and truncate commands in this blog post.
Why use dd or truncate?
dd and truncate are installed by default on most Linux and macOS systems.
You do not have to install anything else.
On macOS:
$ which dd
/bin/dd
$ which truncate
/usr/bin/truncate
On Debian Linux and RedHat Linux:
$ which dd
/usr/bin/dd
$ which truncate
/usr/bin/truncate
Which is faster? dd or truncate?
The truncate command creates a sparse file. It only changes the file size size. The file does not consume actual disk space until data is written to it. Hence, it creates the file immediately.
The dd command is slower because it copies data from the input source using if to the output file of. We can specify block size bs and count. Actual data, null bytes, is written from /dev/zero to the disk.
Create 1GB file
These commands will create a 1GB file 1gbfile.bin with random junk content.
Using dd:
dd if=/dev/zero of=1gbfile.bin bs=1G count=1
Using truncate:
truncate -s 1G 1gbfile.bin
Output:
-rw-r--r-- 1 arul staff 1.0G Dec 16 23:15 1gbfile.bin
Create 2GB file
These commands will create a 2GB file 2gbfile.bin with random junk content.
bs stands for block size. Note that when the file is greater than 2GB, we will use the seek option and set block size to 1.
Using dd:
dd if=/dev/zero of=2gbfile.bin bs=1 count=0 seek=2G
Using truncate:
truncate -s 2G 2gbfile.bin
Output:
-rw-r--r-- 1 arul staff 2.0G Dec 16 23:14 2gbfile.bin
Create 5GB file
These commands will create a 5GB file fivegbfile.bin with random junk content.
Using dd:
dd if=/dev/zero of=fivegbfile.bin bs=1 count=0 seek=5G
Using truncate:
truncate -s 5G fivegbfile.bin
Output:
-rw-r--r-- 1 arul staff 5.0G Dec 16 23:16 fivegbfile.bin
Create 10GB file
These commands will create a 10GB file tengbfile.bin with random junk content.
Using dd:
dd if=/dev/zero of=tengbfile.bin bs=1 count=0 seek=10G
Using truncate:
truncate -s 10G tengbfile.bin
Output:
-rw-r--r-- 1 arul staff 10G Dec 16 23:17 tengbfile.bin
Create 15GB file
These commands will create a 15GB file 15gbfile.bin with random junk content.
Using dd:
dd if=/dev/zero of=15gbfile.bin bs=1 count=0 seek=15G
Using truncate:
truncate -s 15G 15gbfile.bin
Output:
$ ls -lh *bin
-rw-r--r-- 1 arul staff 15G Dec 16 23:18 15gbfile.bin
Create 20GB file
These commands will create a 20GB file 20gbfile.bin with random junk content.
Using dd:
dd if=/dev/zero of=20gbfile.bin bs=1 count=0 seek=20G
Using truncate:
truncate -s 20G 20gbfile.bin
Output:
$ dd if=/dev/zero of=20gbfile.bin bs=1 count=0 seek=20G
0+0 records in
0+0 records out
0 bytes transferred in 0.000019 secs (0 bytes/sec)
$ ls -lh *bin
-rw-r--r-- 1 arul staff 20G Dec 16 23:20 20gbfile.bin
Create 100GB file
This command will create a 100GB file 100gbfile.bin with random junk content. Just make sure you have enough available disk space before running this command.
Using dd:
dd if=/dev/zero of=100gbfile.bin bs=1 count=0 seek=100G
Using truncate:
truncate -s 100G 100gbfile.bin
Create 1TB file
TO create a 1 terabyte file, first make sure that you have enough disk space on your system.
Using dd:
dd if=/dev/zero of=1tbfile.bin bs=1 count=0 seek=1T
Using truncate:
truncate -s 1T 1tbfile.bin
Conclusion
You can use any command. If you were able to create or not create a file with random junk content, let us know. Hope this blog post was useful. Thanks for reading.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.