When testing disk-space monitoring alerts (such as Nagios or Zabbix filesystem thresholds), network throughput, or backup performance, it is helpful to quickly generate a dummy file of an exact size on Windows or Linux.

This guide covers the built-in commands for creating large test files on both platforms.


Create a Large File in Windows (fsutil)

Windows includes the fsutil file createnew command, which allocates a file of a specified size in bytes almost instantaneously. Run Command Prompt or PowerShell as Administrator:

fsutil file createnew <filename> <size_in_bytes>

Common Byte Size Examples

Target Size Calculation Size in Bytes
100 MB (MiB) 100 * 1024 * 1024 104857600
500 MB (MiB) 500 * 1024 * 1024 524288000
1 GB (GiB) 1 * 1024 * 1024 * 1024 1073741824
50 GB (GiB) 50 * 1024 * 1024 * 1024 53687091200

For example, to create a 500 MiB file (524288000 bytes) or a 50 GiB file (53687091200 bytes):

REM Create a 500 MiB file
fsutil file createnew output-500mb.dat 524288000

REM Create a 50 GiB file
fsutil file createnew output.file.dat 53687091200

In PowerShell, you can also use unit suffixes (MB, GB) directly so you do not have to calculate bytes by hand:

fsutil file createnew output-500mb.dat (500MB)

Create a Large File in Linux

On Linux, you can either preallocate blocks instantaneously using fallocate or write zero-filled blocks to disk using dd.

Method 1: Instant Allocation with fallocate (Fastest)

On modern Linux filesystems (ext4, xfs), fallocate reserves disk blocks immediately without writing zeros to every sector, so even multi-gigabyte files are created in milliseconds:

# Create a 500 MiB file instantly
fallocate -l 500M output.file.dat

Verify the allocated disk usage with ls -lh and du -h:

ls -lh output.file.dat
du -h output.file.dat

(Note: Stay clear of truncate -s 500M when testing disk-space monitoring alerts—truncate creates a sparse file that reports an apparent size of 500 MB in ls -lh while consuming 0 blocks in df -h.)

Method 2: Write Zero-Filled Blocks with dd

When you want to actually exercise disk write I/O or work on a filesystem that does not support fallocate, use dd reading from /dev/zero:

dd if=<input_file> of=<output_file> bs=<block_size> count=<number_of_blocks>
  • Create a 256 MiB file:
    dd if=/dev/zero of=output.file.dat bs=256M count=1 status=progress
    
  • Create a 512 MiB file:
    dd if=/dev/zero of=output.file.dat bs=256M count=2 status=progress
    
  • Create a 1 GiB file (using smaller 64 MiB buffer blocks to reduce RAM usage):
    dd if=/dev/zero of=output.file.dat bs=64M count=16 status=progress
    

Method 3: Non-Compressible Random Data (/dev/urandom)

Zero-filled files compress down to almost nothing, so if you are testing backup compression or WAN replication with deduplication/compression enabled, generate random bytes instead:

dd if=/dev/urandom of=random.file.dat bs=64M count=4 status=progress

Clean Up After Testing

Remember to delete the test files once your monitoring alert or disk test completes:

# Linux
rm -f output.file.dat random.file.dat
REM Windows
del output.file.dat output-500mb.dat

References