How to Quickly Create Large Files on Linux with dd, truncate, and fallocate
Learn practical Linux commands—dd, truncate, and fallocate—to generate large files of specific sizes for testing or troubleshooting, with clear examples and tips on choosing the fastest method.
When testing or troubleshooting, you may need empty files of a specific size (e.g., 500 MB or 2 GB) instead of creating a zero‑byte file and filling it manually.
Using dd command to create large files
The dd utility copies and converts files; it is often used for creating bootable USB drives. It writes directly to disk, so the speed depends on the disk’s read/write performance.
Example: create a 2 GB file named rumenz.img: dd if=/dev/zero of=rumenz.img bs=2G count=1 You can adjust block size and count, e.g., bs=1M count=1024 to obtain a 1 GB file.
Using truncate command to create large files
The truncate command expands or shrinks a file to a specified size using the -s option.
Example: create a 2 GB file: truncate -s 2G rumenz.img Verify the file with ls -lh rumenz.img. By default, if the target file does not exist, truncate creates it; the -c option can prevent creating a new file.
Using fallocate command to create large files
fallocateis the fastest method for creating large files because it allocates space directly.
Example: create a 1 GB file: fallocate -l 1G rumenz.img Check the result with ls -lh rumenz.img.
Conclusion
The files created by dd and truncate are sparse files, meaning their apparent size differs from the actual disk space used. In contrast, fallocate creates non‑sparse files and does so more quickly, making it the preferred choice for generating large files.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
