Create Large Files in Linux Instantly: dd vs truncate vs fallocate
This article explains three Linux commands—dd, truncate, and fallocate—for quickly creating large files of specific sizes, comparing their mechanisms, speed, and whether they produce sparse files, with practical examples for generating 2GB test files.
Using dd Command to Create Large Files
The dd command copies and converts files, commonly used for creating bootable USB drives. It writes directly to disk, so creation speed depends on disk I/O and file size.
To create a 2 GB file named rumenz.img: dd if=/dev/zero of=rumenz.img bs=2G count=1 Adjust block size ( bs) and count ( count) as needed; for example, bs=1M count=1024 yields a 1 GB file.
Using truncate Command to Create Large Files
The truncate command shrinks or extends a file to a specified size using the -s option.
Create a 2 GB file: truncate -s 2G rumenz.img Verify with ls -lh rumenz.img. By default, truncate creates the file if it does not exist; use -c to avoid creating new files.
Using fallocate Command to Create Large Files
fallocateis the recommended method because it allocates space instantly without writing data, making it the fastest.
Create a 1 GB file: fallocate -l 1G rumenz.img Check the result with ls -lh rumenz.img.
Conclusion: Sparse Files vs. Allocated Space
ddand truncate produce sparse files — files whose apparent size (maximum logical size) differs from the actual disk space allocated. fallocate allocates real disk blocks, so the file is not sparse and consumes physical storage immediately. This allocation speed advantage is why fallocate is preferred for quick large-file creation.
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.
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical 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.
