Generate fake files of any size in macOS and Linux
Oftentimes when working with applications, for the sake of testing things out we need placeholder files. For instance, if we have a file upload functionality, we may want to test it for a certain file type of a certain size.
So, if we want to test if the file upload functionality restricts uploading PDF files to not more than 10 MBs, we need a PDF file with a size of more than 10 MBs for it to fail.
It could be possible, we may not have the exact file of this size and that’s where these little utilities in macOS and Linux can come in handy.
mkfile utility in macOS
mkfile utility in macOS lets you create fake files of any size you may need.
So, for instance, if we want a PDF file of size 10 MB, here’s how you can generate it.
$ mkfile 10m fakefile.pdf
This will generate the desired PDF file at the specified location. You might not be able to open it since it’s just a fake file built using random binaries but it will get your job done.
Here are few more examples.
$ mkfile 5m fakeimage.png $ mkfile 15m fakevideo.mp4
truncate utility in Linux
If you want to achieve the same in Linux, it has got the
truncate utility which will essentially let you do that.
Here’s how you can do it.
$ truncate -s 10m fakefile.pdf
-s option lets you specify the size of the file.
👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!