0

I am trying to understand why the following sequence of commands (in a MAC OSX terminal) produce a different checksum between the first and second iterations.

$ tar czf General.tar.gz General/
$ shasum -a 256 General.tar.gz  
e722ed697871c611cf08dcd2085aefb017efcc6cf87986afa34b9ca4d70ac077  General.tar.gz
$ rm General.tar.gz 
$ tar czf General.tar.gz General/
$ shasum -a 256 General.tar.gz  
b2b2b0a2a3d243a561861cfa4af82e1b930254c4cbec3e20b48dfa4c10bbb91d  General.tar.gz

Basically, I am compressing (using tar) a folder at two different times with no changes in between as far as the contents of the folder is concerned. So, I would expect the .tar.gz file checksum to be the same between the first and second iterations. In fact, this is what I see when I did this in Windows, but it doesn't work this way in MAC OSX. What is the reason for this?

Also, is there a way I can make this work the same way as in Windows? Basically, I am trying to compress files in a directory before sending them over the network and I don't want to do it unless the file/directory contents themselves change.

Thanks in advance for your help !

Vijay
  • 91
  • 5
  • "at two different times" is the important bit – Amadan Apr 11 '16 at 01:19
  • As for how to do it, [Linux: compute a single hash for a given folder & contents?](http://stackoverflow.com/questions/545387/linux-compute-a-single-hash-for-a-given-folder-contents) – Amadan Apr 11 '16 at 01:20
  • Got it. It looks like gzip is adding a timestamp that causes the file contents to differ. Just using "tar cf" instead of "tar czf" gives the expected result. So, I'll just need to modify my procedure to do the tar first, generate the checksum and then gzip it later. Thanks for the helpful links ! – Vijay Apr 11 '16 at 02:07

0 Answers0