I would like to add 8 bytes of data to the beginning of a binary file.

Is there a Linux command for this?

link|improve this question
feedback

2 Answers

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.

link|improve this answer
feedback

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.

or:

% 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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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