首页 > 解决方案 > 比较来自 zip 文件中 2 个不同路径的 2 个文件名(如果可能,包括内容)

问题描述

有没有办法使用 shell 脚本比较 zip 文件中 2 个不同路径的文件名(如果可能,包括内容)?

我要比较的文件:

是否有任何脚本或代码或命令可以用来比较这些 zip 文件中的文件?

标签: bashshellcomparezipdiff

解决方案


这是为以下用途而设计的用例diffoscope

$ echo 1 > foo
$ echo 2 > bar
$ echo 3 > baz
$ zip 1.zip foo bar baz
  adding: foo (stored 0%)
  adding: bar (stored 0%)
  adding: baz (stored 0%)
$ rm baz
$ echo 4 > foo
$ zip 2.zip foo bar
  adding: foo (stored 0%)
  adding: bar (stored 0%)
$ diffoscope --no-progress 1.zip 2.zip 
--- 1.zip
+++ 2.zip
├── zipinfo /dev/stdin
│ @@ -1,5 +1,4 @@
│ -Zip file size: 430 bytes, number of entries: 3
│ --rw-r--r--  3.0 unx        2 tx stor 18-May-24 03:46 foo
│ +Zip file size: 294 bytes, number of entries: 2
│ +-rw-r--r--  3.0 unx        2 tx stor 18-May-24 03:47 foo
│  -rw-r--r--  3.0 unx        2 tx stor 18-May-24 03:46 bar
│ --rw-r--r--  3.0 unx        2 tx stor 18-May-24 03:46 baz
│ -3 files, 6 bytes uncompressed, 6 bytes compressed:  0.0%
│ +2 files, 4 bytes uncompressed, 4 bytes compressed:  0.0%
├── foo
│ @@ -1 +1 @@
│ -1
│ +4

推荐阅读