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?


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

| improve this answer | |
  • 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
  • 1
    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
  • 1
    @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

I posted the longer explanation at "diff files inside of zip without extracting it" but if you want to compare the contents of the files within the zipfile and ignore all the metadata (timestamps in particular) then you should run:

diff \
  <(unzip -vqq file1.zip | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3) \
  <(unzip -vqq file2.zip | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3)
| improve this answer | |

You should try zipcmp if you prefer to save keystrokes https://libzip.org/documentation/zipcmp.html

| improve this answer | |
  • Could you add some explation as to how the link would be used to answer the question? What does it take to install (if necessary), configure, and use the program to solve the OP's question? Thank you! – Jeff Schaller Jun 7 at 12:59

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.