What?
How to create a file of any given size on linux
Why?
Quick testing, ballast, and dummy file creation.
How?
Create a single 100K file1
truncate -s 100K testfile.bin
or
fallocate -l $((100*1024)) testfile.bin
Create a single 100K file filled with zeros
head -c 100K /dev/zero > testfile.bin
or
dd if=/dev/zero of=testfile.bin bs=100K count=1
or
dd if=/dev/zero of=testfile.bin bs=1K count=100
on Mac, use:
# prefers lowercase
dd if=/dev/zero of=testfile.bin bs=100k count=1
Create a single 100K file filled with random bytes
head -c 100K /dev/random > testfile.bin
or
dd if=/dev/random of=testfile.bin bs=100K count=1
or
dd if=/dev/random of=testfile.bin bs=1K count=100
on Mac, use:
# prefers lowercase
dd if=/dev/random of=testfile.bin bs=100k count=1
Footnotes
-
Note that a truncated file may not necessary have the real space allocated to it and therefore will be subject to certain optimizations with respect to syscalls that may not apply to other file types. ↩