6

I have two tar archives (compressed or not compressed), and I want to find all differences in the two archives. Both archives contain a complete file system (i.e. when unpacked, would generate directories like /bin, /home, /root, /usr, /var, /etc,... I hope you get the point). I want to have a list of the following:

  • New files
  • Removed files
  • Changed files (content of file, not just size)
  • Changed symlinks (both relative and absolute)
  • New/removed symlinks

I cannot just unpack those archives and use diff, as diff will not correctly recognize absolute symlinks (as they would point out of the file system structure of the archive).

Is there another way to compare the content of two tar archives?

5
  • git may be able to handle symlinks, which would give you the ability to use git diff. It'd still involve unpacking into a subdir, though. Commented Nov 12, 2013 at 13:24
  • Supposing I have the archives in two subdirs, I tried git diff --no-index dir1 dir2 but get an error: file/directory conflict: dir1/xxx dir2/xxx. Commented Nov 12, 2013 at 13:27
  • that's really unfortunate... and the workaround (renaming directories to d-name, files to f-name, links to l-name) is silly. Commented Nov 12, 2013 at 13:37
  • As a first step, you can compare the archive's contents, that will at least tell you if you have new/removed files and symlinks (no changed ones though): diff <(tar -tf a.tar) <(tar -tf b.tar). Commented Nov 12, 2013 at 14:12
  • Same question on Stackoverflow: stackoverflow.com/q/19930300/1184892 Commented Feb 2, 2020 at 10:44

2 Answers 2

2

I don't think you'll get anything useful from diff if you have symbolic links to compare as such. Instead of trying to do it all in one go, do two separate passes: one to compare metadata, and one to compare file contents.

If you have no exotic file names, a simple comparison of the output of tar -tv or pax -v is sufficient for the metadata part. In bash/ksh/zsh:

pax -v <(archive1.tar) <(archive2.tar) 

For the content of the archive, mount them with avfs and compare the two directory trees.

mountavfs diff -urN ~/.avfs$PWD/archive1.tar\#/ ~/.avfs$PWD/archive2.tar\#/ 
2

I have solved this by an additional bash alias, which does the following:

  • Extract the two tar-files a specific temp folder
  • Call diff tool meld
  • Delete the folders

To enable this add the following line to your ~/.bashrc

function meldtar() { d1=/tmp/$(basename $1)_$(date +%s) ; d2=/tmp/$(basename $2)_$(date +%s) ; mkdir $d1 ; tar -xvf $1 -C $d1 ; mkdir $d2 ; tar -xvf $2 -C $d2 ; meld $d1 $d2 ; rm -rf $d1 $d2 ; } 

Within a bash shell it is now possible to call

meldtar tar1 tar1 

Then meld pops up and shows all the differences same as with standard folders.

Note: Any modification done within meld will get lost.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.