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 file

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

byt on Mac, use:

# prefers lowercase
dd if=/dev/random of=testfile.bin  bs=100k  count=1