Let's say I have a folder Documents
and a TAR file Documents.tar
, how to check if the tar file contains the same files that are present in the directory?
The more obvious solution to me would be to do:
$ tar xvf Documents.tar -C untarDocs
$ diff -r Documents untarDocs
Unfortunately this is very slow for large TAR files, is there any other alternative?
Using tar -dvf Documents.tar
(or --diff, --compare) doesn't work because it doesn't detect a file that is present in the filesystem but not in the TAR file, it just detects a file present in the TAR file but not in the filesystem e.g.:
$ mkdir new
$ touch new/foo{1..4}
$ tar cvf new.tar new/
$ touch new/bar
$ tar --diff --verbose --file=new.tar #### doesn't detect new/bar #########
$ rm new/foo1
$ tar --diff --verbose --file=new.tar
Output
new/
new/foo2
new/foo3
new/foo4
new/foo1
tar: new/foo1: Warning: Cannot stat: No such file or directory ### works ###
diffopts=
to reduce the amount of meta data to compare.