Bash: substitute some bytes in a binary file Bash: substitute some bytes in a binary file bash bash

Bash: substitute some bytes in a binary file


No problem, just add conv=notrunc:

dd if=data.bin of=zero.bin bs=1 count=5 conv=notrunc


You have half of the solution; do that into a temporary file tmp.bin instead of zero.bin, then

dd if=zero.bin bs=1 seek=5 skip=5 of=tmp.binmv zero.bin old.bin # paranoiamv tmp.bin zero.bin


Don't get stuck on using dd(1). There are other tools, eg:

(cat data.bin && tail -c +5 zero.bin) > updated.bin