How to Pad a File to a Desired Size Using dd Command

dd

I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes.

How do I pad it?

This doesn't seem to be working:

cp smallfile.img largerfile.img
dd if=/dev/zero of=largerfile.img bs=1 count=262144

Best Answer

Drop the of=largerfile.txt and append stdout to the file:

dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
Related Question