diff command compares to see any difference betwenn two files. Can the same be used to compare two zip files, i.e if there is any difference in data ,like counts etc in individual files in the zipped files?

  • Is the order in which files are included in the zip archive important for you? – guido Jun 29 '18 at 17:25
  • order doesnt matter, as along the correct files are compared – UnixPhile Jun 29 '18 at 17:27

You will have to unzip them (if only in memory) to compare the two. A cool way I have seen to do this with diff is:

diff -y <(unzip -l file1.zip) <(unzip -l file2.zip)

That will show you if there are any files contained in one and not the other

  • 2
    I was thinking about the same, but adding -qql instead of -l to suppress some noise , and sorting by filename at the end | sort -k4 – guido Jun 29 '18 at 17:29
  • 1
    excellent suggestions @guido! – Jaken551 Jun 29 '18 at 17:31
  • this compares the number of files. But what about the content inside the files? – UnixPhile Jun 29 '18 at 17:42
  • I would unzip the zip files and create two arrays with the files. Then I would use something like cmp to compare nth element of arr1 to nth element of arr2 – Jaken551 Jun 29 '18 at 17:47
  • @UnixPhile diff -y --suppress-common-lines -W 333 <(unzip -lqq file1.zip | sort -k 4) <(unzip -lqq /file2.zip | sort -k 4) will suppress same entries and show missed/extra files as well as files different in size or timestamp. -W is about width, should be reasonably big for looong/path/to/files. Comparing by content will take more effort, let me know if that's really required. – Tagwint Jun 29 '18 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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