Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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'd like to embed checksum information into file, that I transfer. It's tar.gz or tar.xz file and I can only transfer one file to remote side.

How do you recommend I embed checksum information?

I want checksum of whole archive, not it's contents (I'd like to check it's integrity "before" unpacking).

I know I could pack it again in some format supporting checksums (like rar) but it's computational cost to "repack" stuff, just for adding checksum (on the other hand I don't like rar format). So preffered would be sth like gzip & gunzip etc , but for adding, checking, and removing checksum.

Any tools, ideas, scripts, workarounds?

Am I right .xz and .gz support concatentation? Maybe it's worth to use this feature to append compressed checksum on the end of file ?

share|improve this question
Low-tech solution that sometimes works (and sometimes not): do your archive, calculate checksum, rename the file to include the checksum (blah.tar.gz.AB2ED362...). – Mat Nov 22 '11 at 11:35
Good point. Unfortunately In my case, there "is no filename" - file contents are send with tcp (so there is no filename) ans it's the only file. – Grzegorz Wierzowiecki Nov 22 '11 at 16:48
up vote 5 down vote accepted
cat file.gz file.gz.sig > transfer_me.signed

Then, on the remote host, you split out the appended checksum using

tail -c length_of_the_checksum_info transfer_me.signed > file.gz.sig
head -c -length_of_the_checksum_info transfer_me.signed > file.gz

Note the minus in the second command. The length depends on the type of checksum you use. You can have just

md5sum file.gz | cut -d ' ' -f 1 > file.gz.sig

Notice also, that in this way you can also unpack the transfer_me.signed file straight away without splitting, because tar will ignore the trailing "garbage".

A similar solution, with additional encryption or scrambling mechanisms, is used for signing updates for many mobile devices - for example the Amazon Kindles. But in their case, archive file identification is undesired, so they put all the fingerprinting information at the beginning of an update file.

share|improve this answer
Thanks for great answer and educative noteces :). That exactly solves my problems. Your notices are precious here "unpack the transfer_me.signed file straight away without splitting, because tar will ignore the trailing "garbage" " - I haven't knew about it. And another tip, about design of mobile devices :). – Grzegorz Wierzowiecki Nov 22 '11 at 16:52

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.