linux - Why does tar with -z option create archive with different hash everytime

08
2014-07
  • Questioner

    Can you tell me why

    tar czf archive.tar dir
    

    creates archive with different hash everytime (I check with 'md5sum') Without compression parameter -z or with parameter -j instead all works fine. Thanks

  • Answers
  • ortang

    That is because gzip stores meta-information too when using default parameters. Take a look at the -n parameter of gzip to discard that information, then you should have identical archives every time, assuming the files did not change.

    Try something like: tar -cf <archive_dir> | gzip -n > archive_dir.tar.gz

    Take a look at the gzip manpage.


  • Related Question

    linux - Why is "tar" trying to create an empty archive?
  • snostorm

    I'm trying to use tar to tar files before transfer, so I can keep the entire file path rather than losing it along the way. However, when I try to tar an empty folder, it tells me that it is cowardly refusing to create an empty archive. I want to keep the empty folder on the other end, but don't want to put anything else into the archive to make it non-empty. Is there any way to do this?


  • Related Answers
  • Josh

    What command are you using? I am able to create a tar archive of an empty directory just fine:

    [jnet@Stan tmp]$ mkdir test
    [jnet@Stan tmp]$ tar -cf test.tar test
    [jnet@Stan tmp]$ ls -lh test.tar 
    -rw-r--r--  1 jnet  wheel    10K Apr 20 21:58 test.tar