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

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

2 Answers 2

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

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.