Search This Blog

Linux: create a file with specific size

1. create an 1M bytes file:
dd if=/dev/zero of=output.dat  bs=1024  count=1024

2. You can also use K / M / G as extension for bs (block size).
dd if=/dev/zero of=output.dat bs=1M count=1

creates a 1M bytes file 3. The above examples create zero-filled file using /dev/zero, You can also use if=/dev/urandom to fill the file with random data instead of zeros. e.g.
dd if=/dev/urandom of=output.dat bs=1M count=1

4. Create a number of files:
for ((i=1; i<=100; i++)); do
    n=$(printf "%03d" $i)
    dd if=/dev/urandom of=16KB_${n}.dat bs=1024 count=16
done
or for BASH 4+
for i in {001..100}; do
    dd if=/dev/urandom of=16KB_${i}.dat bs=1024 count=16
done

4. See also this post.

No comments:

Post a Comment