Create Large File Using fallocate
If you need to create a large test file on Linux, fallocate
can help.
To create a 1GB file:
fallocate -l 1G test.img
If you need a different size, just change the -l
option with the proper suffix.
- -l 15k
= 15KB
- -l 15m
= 15MB
- -l 15g
= 15GB
- -l 15t
= 15TB
- -l 15p
= 15PB
If your operating system does not support fallocate
, you can always rely on the dd
command.
To create a 1GB file:
dd if=/dev/zero of=/path/to/your/output/file bs=1024 count=1024000
Since dd
is more complicated, here are what these inputs mean:
- if=
is your input, we’re using /dev/zero
to generate junk data.
- of=
is your output.
- bs=
is the number of bytes read and written at a time.
- count=
is the number of input blocks we are copying, or how many times we want to run the bs=
input.
Based on the above inputs, you just need to change the value of count=
to increase/decrease the file size.
- count=1024
= 1MB
- count=10240
= 10MB
- count=102400
= 100MB