5

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. 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.
    – Alex
    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. 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).
    – terdon
    Nov 12, 2013 at 14:12
  • Same question on Stackoverflow: stackoverflow.com/q/19930300/1184892
    – crw
    Feb 2, 2020 at 10:44

1 Answer 1

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\#/

You must log in to answer this question.

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