Make Empty Files Of A Certain Size In OS X

Previously, I’ve used a few methods to create files in OS X using touch, dd, etc. But the easiest way to create empty files is using the mkfile command, which instantly creates a file of any size. To use the mkfile command, use the following general syntax: mkfile -n size[b|k|m|g] filename Using the above, to create a 2GB file called “TESTFILE” on the desktop, use the following command: mkfile -n 2g ~/Desktop/TESTFILE The file is created instantly and occupies the desired space on the disk. If you cat the file you should see a whole lot of zeros. I use dd for testing throughput (e.g. to large storage arrays) as there are more options, but mkfile is a useful tool as well. When you use Disk Utility to generate files, you’re basically just piping to mkfile, so this gives you a programmatic way to do so from the command line. Enjoy.