0

Is it possible to verify that a tar archive has been extracted correctly? Like a checksum of the extracted directory?

For some reason, certain files extracted by tar are erroneously created as empty files. It would be nice to detect this, like so:

$ tar xzf foo.tgz
$ <SOME_MAGIC_COMMAND>
  Error: foo/bar does not match file in archive
1

You can use the --compare option of tar. From man tar:

   tar {--diff|--compare} [--file ARCHIVE] [OPTIONS] [FILE...]

   -d, --diff, --compare
          Find differences between archive and file system.   The
          arguments  are  optional and specify archive members to
          compare.  If not given, the current  working  directory
          is assumed.

Example run with a.txt, b.txt, c.txt and d.txt in archive.tgz:

$ tar -df archive.tgz
tar: a.txt: Warning: Cannot stat: No such file or directory
c.txt: Mod time differs
c.txt: Size differs
d.txt: Mod time differs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.