diff files inside of zip without extracting it

Gum Bi picture Gum Bi · Feb 23, 2016 · Viewed 18.5k times · Source

Is there any way to perform diff operetion on two files in two zips without extracting them? If not - any other workaround to compare them without extracting?

Thanks.

Answer

Mark Howard picture Mark Howard · May 26, 2017

Combining the responses so far, the following bash function will compare the file listings from the zip files. The listings include verbose output (unzip -v), so checksums can be compared. Output is sorted by filename (sort -k8) to allow side by side comparison and the diff output expanded (W200) so the filenames are visible int he side by side view.

function zipdiff() { diff -W200 -y <(unzip -vql $1 | sort -k8) <(unzip -vql $2 | sort -k8); }

This can be added to your ~/.bashrc file to be used from any console. It can be used with zipdiff a.zip b.zip. Piping the output to less or redirecting to a file is helpful for large zip files.