3

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?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • you could use python to enumerate the content of each tar archive. It's not really an answer; it's a direction to use. There's a non trivial amount of effort required to get it to work properly – Anya Shenanigans Nov 12 '13 at 13:22
  • If there is no way to do this in one line, than there is not. I just want to hear input from experts, if such a tool exists or can be put together by some standard unix tools. – Alex Nov 12 '13 at 13:24
  • I haven't thought that through, but `rsync` has pretty good recursive comparison capabilities. So, you could try `rsync -nPavH ` and see if you can reasonably parse it's output. Also, if this is going into the right direction, I think, there is also `librsync`. – Tilman Vogel Nov 12 '13 at 13:38
  • Is this a duplicate of https://stackoverflow.com/questions/1030545/how-to-compare-two-tarballs-content? Some of the utilities mentioned there (pkgdiff, archdiff) might be good. – Daniel H Jun 13 '17 at 17:26
  • Same question on Unix & Linux: https://unix.stackexchange.com/q/100889/34251 – crw Feb 02 '20 at 10:47

1 Answers1

4

The best I can think of is to use:

tar -tvf archive.tar

to list the contents of the file.

Something like:

tar -tvf archive1.tar > list1
tar -tvf archive2.tar > list2
diff list1 list2
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319