Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way I can diff a gzipped tarball against an existing directory?

I would like to be able to do it without extracting the data from the tarball.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

Mount the tarball as a directory, for example with AVFS. Then use diff -r on the real directory and the point where the tarball is mounted.

mountavfs
diff -r ~/.avfs/path/to/foo.tar.gz\# real-directory
share|improve this answer
    
What is the \# for? –  Annan Oct 3 '12 at 17:59
    
@Annan AVFS exposes the contents of an archive as a directory whose name is the name of the archive file with a # appended. The backslash is unnecessary in most shells. –  Gilles Oct 3 '12 at 18:05
add comment

Turns out that GNU tar has diff built in (-d):

$ #Create the archive and a difference:
$ echo one>file1;echo two>file2;tar -czf archive.tgz file*;echo changing>>file1
$ tar -dzf archive.tgz
file1: Size differs

If you are working with tar that does not have this try:

$ for F in `tar -tzf archive.tgz`;do tar -xzOf archive.tgz $F|diff --brief - $F;done
Files - and file1 differ
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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