Generate File of a certain size?
I'd like to generate a file with the name
example.file. I could use
but I want the file to be exactly 24MB in size. I already checked the manpage of touch, but there is no parameter like this. Is there an easy way to generate files of a certain size?
You can use dd:
dd if=/dev/zero of=output.dat bs=24M count=1
dd if=/dev/zero of=output.dat bs=1M count=24
or, on Mac,
dd if=/dev/zero of=output.dat bs=1m count=24
On the Mac, use 24m (small m), because the Mac doesn't like the big M. `dd if=/dev/zero of=output.dat bs=24m count=1`
On Android (5.1.1, might (not) be version or phone specific) I had to use a lowercase `m` too.
What is the problem with large block sizes specifically? I had hoped to use a 1G block size for a 1G file.
Note that this doesn’t create a 24 MB file, but a 24 **MiB** one (=~ 25,2 MB) – for a 24 MB file use `bs=24MB` or `bs=1MB` respectively. I suppose it’s `mb` on a Mac.