Create a large file on macOSAugust 8, 2022
I won't present how to generate a valid file (audio, video, text, pdf) as the issue is more complex. Instead, we will focus on generating files of specific sizes.
1# mkfile FILE_SIZE FILE_NAME.FILE_EXTENSION2mkfile 100m test.pdf
Imagine you need to test something, and you need to have a file of a specific size (or file bigger than
n MB). What would you do?
You would probably try to find some files on your local drive or the internet. You will be successful after a few moments, but is it easiest to do that? What if you need to test multiple file sizes? Finding the right file with the right size would take a long time. So what are the other options, you might ask? The answer is simple - the
The official description is following:
mkfile creates one or more files that are suitable for use as NFS-mounted swap areas. The sticky bit is set, and the file is padded with zeroes by default. Non-root users must set the sticky bit using chmod(1). The default size unit is bytes, but the following suffixes may be used to multiply by the given factor: b (512), k (1024), m (1048576), and g (1073741824).
But to be honest, this description is not really beginner friendly. So what does
mkfile, and how can we use it?
mkfile creates a file of a specified size with "dummy" data (You can create a file with a PDF extension, but it won't be a proper/valid PDF). To create a file, you can run the following command:
mkfile 100m test.pdf. It will generate a file that will have +- 100MB, and the name will be
Sometimes you have a "right" file for your testing; if not, instead of trying to find a proper file, create one to match your needs!