Operations 4 min read

How to Quickly Create Large Files on Linux Using dd, truncate, and fallocate

When you need a file of a specific size for testing or troubleshooting on Linux, you can use the dd, truncate, or fallocate commands to generate large files efficiently without manually writing data.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Quickly Create Large Files on Linux Using dd, truncate, and fallocate

Using dd to create a large file

The dd utility copies and converts data; it can write zeros from /dev/zero to a file of any size. For example, to create a 2 GB file named rumenz.img: dd if=/dev/zero of=rumenz.img bs=2G count=1 You can adjust the block size ( bs) and count to achieve other sizes, such as bs=1M count=1024 for a 1 GB file.

Using truncate to create a large file

The truncate command expands or shrinks a file to a specified length with the -s option. To create a 2 GB file: truncate -s 2G rumenz.img After creation, you can verify the size with ls -lh rumenz.img. By default truncate creates a new file if it does not exist; the -c option prevents creation of a new file.

Using fallocate to create a large file

fallocate

pre‑allocates space and is the fastest method for creating large files because it does not write actual data. To create a 1 GB file: fallocate -l 1G rumenz.img Check the result with ls -lh rumenz.img.

Conclusion

Both dd and truncate produce sparse files, which appear large but occupy less physical disk space until data is written. In contrast, fallocate creates a non‑sparse file that immediately reserves the full size on disk, making it the preferred choice when speed and actual allocation are required.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineTRUNCATEddfallocatefile creation
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.