是否可以验证 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.txt
和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