2

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?

0

1 Answer 1

4

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

and

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

You must log in to answer this question.

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