验证解压的 tar 存档

验证解压的 tar 存档

是否可以验证 tar 存档是否已正确提取?就像提取目录的校验和一样?

由于某种原因,tar 提取的某些文件被错误地创建为空文件。最好能检测到这一点,如下所示:

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

答案1

您可以使用--compare的选项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.

a.txt使用, b.txt,c.txtd.txtin运行的示例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

相关内容