Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large (binary) file that has some corruption near the beginning.

Then, I have a second, smaller file that I obtain by starting to download the same file again, but interrupt after I have enough bytes to fix the original one.

My question is, how do I simply overwrite the beginning of the large file with the contents of the second, smaller file? I could use cat, tail and head, but that would create a copy of the file. There must be a more efficient way.

Oh yes, and I'm looking for a linux command-line solution, if that wasn't obvious. I'm using bash, but I have other shells if that helps.

share|improve this question
up vote 3 down vote accepted
dd conv=notrunc if=good_header of=corrupted_file

The conv=notrunc option is essential here.

share|improve this answer
Awesome, this is exactly what I needed. I keep forgetting that dd works on ordinary files as well :) (I can accept your answer in two minutes.) – Attila O. Dec 15 '12 at 22:45
Obviously an awesome answer (I was about to write the same thing). +1. – gniourf_gniourf Dec 15 '12 at 23:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .