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.
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.img02What 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
!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.bin05Sources
- mkfile — create a file of a given size (macOS)Evidence: Documents size suffixes (b/k/m/g) and the -n flag that creates a file without writing data.
Last verified: 2026-09-17 · Category: Files & Folders