On Ubuntu 22.04, I found these 2 methods will get different sha256 of archive_tgz

tar czf /a/archive_tgz . 

tar czf /dev/stdout . | split -d -b 200M - /a/archive. && cat /a/archive.* > /a/archive_tgz

Is it normal or about block size of file? What's the difference?


1 Answer 1


The difference is because modification time of . changes and it is included in the tar file (tar czf archive.tgz . updates .).

tar czf /dev/stdout . | sha256sum


tar czf archive.tgz .
sha256sum archive.tgz

already give different hashes (without split). It also warns tar: .: file changed as we read it.

Writing to a different directory so .'s modification time is unchanged gives the same hash.

tar czf ../archive.tgz .
sha256sum ../archive.tgz

You can also verify it isn't split's problem by comparing the hashes:

tar czf single-archive.tgz .

split -d -b 200M - single-archive.tgz archive. && cat archive.* >archive-combined.tgz

md5sum single-archive.tgz
md5sum archive-combined.tgz
  • Sorry, I didn't describe my problem clearly and I modify it. I do write them to a different directory.
    – Azreal
    Commented May 31, 2023 at 6:19
  • 1
    @Azreal it is because it is padded with null bytes. See unix.stackexchange.com/q/747693/272821 for details.
    – wjwrpoyob
    Commented May 31, 2023 at 23:11
  • 1
    You can fix by using - instead of /dev/stdout.
    – wjwrpoyob
    Commented May 31, 2023 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .