15

I know that you can use -W when creating an archive, but how do you verify and already-created archive? tvWf says it's not a valid tar archive?

$ mkdir tmp
$ echo asdkfjh > tmp/a
$ echo qweroiu > tmp/b
$ ls
tmp
$ tar cvf archive.tar tmp
tmp/
tmp/a
tmp/b
$ tar tvWf archive.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: VERIFY FAILURE: 1 invalid header detected
tar: Error exit delayed from previous errors

Same thing happens with both tar 1.15 (which is the system default on centos 5) and 1.26 (which is the newest version from gnu).

4 Answers 4

16

GNU tar has a --compare option. See the Comparing Archive Members with the File System section of the documentation for details.

2
  • 5
    E.g. tar -df /path/to/archive.tar.bz2 will show differences between files in the archive and the filesystem, resolving relative paths in the archive against the current working directory.
    – Walf
    Mar 2, 2017 at 1:01
  • Yes. This is the answer. tar -df folder.tar.bz2 does verify it. Add -v for verbose. On the other hand, -W or --verify do not work with compressed archives. It only works like tar -cvWf folder.tar folder. It verifies right after creating the archive, as it says in the man page.
    – midnite
    Dec 29, 2021 at 13:35
8

You can't use W with t.

mkdir tmp
echo bdb > tmp/a
echo bdb > tmp/b

tar cvf archive.tar tmp
tmp/
tmp/a
tmp/b

ls -l archive.tar
-rw-r--r-- 1 tony tony 10240 Jun 23 05:57 archive.tar

tar tvf archive.tar
drwxr-sr-x tony/tony         0 2011-06-23 05:57 tmp/
-rw-r--r-- tony/tony         4 2011-06-23 05:57 tmp/a
-rw-r--r-- tony/tony         4 2011-06-23 05:57 tmp/b

tar tvWf archive.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

I believe t alone is enough to test the archive.

3
  • 1
    t alone just lists the content of the archive. I want to verify that the files in the tar have the same contents as the originals (still on the file system), which I thought was what W should do (right?).
    – cespinoza
    Jun 23, 2011 at 22:01
  • 2
    W does that only when writing the archive. If you want to make sure the content is a byte for byte match you'll have to extract it somewhere and diff/sum the files. Jun 23, 2011 at 22:29
  • 1
    Not for me: tar tvWf t.tar tar: --verify cannot be used with -t: tar (GNU tar) 1.27.1
    – Tom Hale
    Nov 2, 2016 at 10:18
3

Joerg Schillings star sports a diff option, which is able to compare files in a tar archive with their original. You can state what should be recognized as difference.

0 1 newt pts/1 ~ 17> :> tmp/testfile
0 1 newt pts/1 ~ 19> star -cz tmp > tmp.tar
0 1 newt pts/1 ~ 19> echo bla > tmp/testfile
0 1 newt pts/1 ~ 20> star -z -diff diffopts=not,times < tmp.tar
diffopts=perm,symperm,type,nlink,uid,gid,uname,gname,size,data,rdev,hardlink,symlink,sympath,sparse,dir,acl,xattr,fflags
tmp/testfile: different size,data
star: 115 blocks + 0 bytes (total of 1177600 bytes = 1150.00k).

Note that it mentioned testfile as being of different size and data. If I hadn't excluded times (including access time!) it would have stated the access time as well, and also list all files whose times had changed just by looking at them.

Since the demise of BerliOS, star can be found at sourceforge. It is highly portable, and compiles painlessly on most unixoid systems and unixoid look-alikes.

1
  • Recent sources are in the schilytools source package.
    – schily
    Jun 27, 2018 at 21:15
0

The verification option is meant to be used during the creation, not after. Also, compression is added afterwards.

%> tar -cvpWlf  test.tar sh.save
sh.save/
sh.save/test.tar
sh.save/Downloads/
sh.save/mount.sh
sh.save/Documents/
sh.save/skip_dirs_in_find.sh
Verify sh.save/
Verify sh.save/test.tar
Verify sh.save/Downloads/
Verify sh.save/mount.sh
Verify sh.save/Documents/
Verify sh.save/skip_dirs_in_find.sh

Although tar offers the "--compare" option.

man tar:

-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.

You must log in to answer this question.

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