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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

Here is a new tool: http://diffoscope.org/

Older tool: http://tardiff.sourceforge.net/

share|improve this answer

Your Answer


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.