Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 would like to add 8 bytes of data to the beginning of a binary file.

Is there a Linux command for this?

share|improve this question

Here is one way to do that.

printf "\x68\x65\x6c\x6c\x6f\x20\x77\x6f" | cat - oldfile > newfile

The argument to printf is a sequence of 8 bytes in hex. Just replace the values I used (which are the ASCII characters "hello wo") with yours.

share|improve this answer
This should be an accepted answer. – Dmitry Volosnykh Jun 15 at 9:25

it is not 'the' command, it is 'a bunch of commands' (in good old unix tradition):

  • put your 8 bytes to a file
  • append the original file to that file
  • rename the new file to the name of the original file.


% echo -n "12345689" > new_file
% cat original >> new_file
% mv new_file original

or, if you need to read the 8 bytes from somewhere else:

% dd if=inputstream of=new_file bs=1 count=8

and then continue as above.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.