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.binor
fallocate -l $((100*1024)) testfile.binCreate a single 100K file filled with zeros
head -c 100K /dev/zero > testfile.binor
dd if=/dev/zero of=testfile.bin bs=100K count=1or
dd if=/dev/zero of=testfile.bin bs=1K count=100on Mac, use:
# prefers lowercase
dd if=/dev/zero of=testfile.bin bs=100k count=1Create a single 100K file filled with random bytes
head -c 100K /dev/random > testfile.binor
dd if=/dev/random of=testfile.bin bs=100K count=1or
dd if=/dev/random of=testfile.bin bs=1K count=100on Mac, use:
# prefers lowercase
dd if=/dev/random of=testfile.bin bs=100k count=1Footnotes
-
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. ↩