4

I have a binary file zero.bin which contains 10 bytes of 0x00, and a data file data.bin which contains 5 bytes of 0x01. I want to substitute the first 5 bytes of the zero.bin with data.bin. I have tried

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

but, the zero.bin is truncated, finally it becomes 5 bytes of 0x01. I want to keep the tailing 5 bytes of 0x00.

Dagang
  • 24,586
  • 26
  • 88
  • 133

3 Answers3

9

No problem, just add conv=notrunc:

dd if=data.bin of=zero.bin bs=1 count=5 conv=notrunc
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
1

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.bin
mv zero.bin old.bin # paranoia
mv tmp.bin zero.bin
geekosaur
  • 59,309
  • 11
  • 123
  • 114
0

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

(cat data.bin && tail -c +5 zero.bin) > updated.bin
Jonathan
  • 859
  • 7
  • 15