← Back toFront-end Tips

Create a file of any size

Written byPhuoc Nguyen
19 Mar, 2021
Last updated
08 Sep, 2022
Sometimes we need big files for testing purposes, without any concern for the files' content. For example, when testing uploads, downloads & responding to changes in network performance, we are likely to want files of various sizes.
macOS comes with a helpful utility command to create a file of any size over 512 bytes called `mkfile`:
In the `FILE_SIZE` option, we can optionally use a suffixes to note the unit of the value `b` - bytes (the deafult), `k` - kilobytes, `m` - megabytes or `g` - gigabytes.
For example, the following command produces an empty two gigabyte file named `big-file.ext`:
$ mkfile 2g big-file.ext
Note the following multiplication factors are applied to the `FILE_SIZE` value:
`b`512For 512 bytes: `1b`, for 1kb (1024 bytes): `2b`
`k`1024For 1kb (1024 bytes): `1k`, for 1mb (1,048,576 bytes): `1024k`
`m`1048576For 1mb (1,048,576 bytes): `1m`, for 1gb (1,073,741,824 bytes): `1024m`
`g`1073741824For 1mb (1,073,741,824 bytes): `1g`, for 2gb (2,147,483,648 bytes): `1g`
See the man page for `mkfile` for more information.
$ man mkfile

See also

Questions? 🙋

Do you have any questions? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.