Create a file of a specific size with mkfile

mkfile is a macOS-only utility that allocates a file of an exact size filled with zeros — the classic way to test free-disk-space behavior or network transfers with dummy data.

macOSmkfiledisk-testingdummy-filesLow risk
Run `mkfile 10m testfile.bin` to create a 10 MB file, or add -n to allocate the space without actually writing the data blocks.

01Command

Command
$ mkfile 10m testfile.bin
mkfile -n 1g bigfile.img

02What it does

Size suffixes are bytes, kilobytes, megabytes, and gigabytes (b/k/m/g), and multiple sizes create multiple files in one call. The -n option creates the file sparse-style: the name and apparent size exist but the disk is not filled until data is written, which is handy for quota and sparse-handling tests.

03Risk

RiskLow risk
!Warning: Without -n, mkfile writes every zero byte to disk, so a `mkfile 500g` attempt fails or fills your drive; clean up test files with rm afterwards.

04Undo

Undo
$ rm testfile.bin

05Sources

Last verified: 2026-09-17 · Category: Files & Folders