← Back toFront-end tips

Create a file of any size

Written byPhuoc Nguyen
Created
19 Mar, 2021
Last updated
08 Sep, 2022
Category
Tip
Tags
macOS
Contributors
dylankenneally
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`:
shell
$ mkfile FILE_SIZE FILE_NAME
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`:
shell
$ mkfile 2g big-file.ext
Note the following multiplication factors are applied to the `FILE_SIZE` value:
UnitFactorExamples
`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.
shell
$ man mkfile

See also

If you found this post helpful, please consider giving the repository a star on GitHub or sharing the post on your favorite social networks 😍. Your support would mean a lot to me!

Questions? 🙋

Do you have any questions about front-end development? If so, feel free to create a new issue on GitHub using the button below. I'm happy to help with any topic you'd like to learn more about, even beyond what's covered in this post.
While I have a long list of upcoming topics, I'm always eager to prioritize your questions and ideas for future content. Let's learn and grow together! Sharing knowledge is the best way to elevate ourselves 🥷.
Ask me questions

Recent posts ⚡

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.
Phước Nguyễn