侧边栏壁纸
Linux入门自学网博主等级

每日学一条Linux命令,终成Linux大神

  • 累计撰写 725 篇文章
  • 累计创建 143 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Linux zipinfo命令详解:查看zip压缩文件的信息(附实例教程和注意事项)

Linux zipinfo命令介绍

zipinfo是一个用于列出zip压缩文件的详细信息的命令,它可以显示压缩文件中每个文件的文件名,大小,压缩率,权限,加密状态,压缩方法,版本,操作系统等信息。zipinfo命令是unzip命令的一个链接,它们是同一个程序,但是在一些系统上,zipinfo可能在编译unzip时被省略了。zipinfo命令的输出格式类似于Unix的ls -lunzip -v命令的结合。

Linux zipinfo命令适用的Linux版本

zipinfo命令适用于大多数Linux发行版,如Ubuntu, Debian, Fedora, CentOS等。如果某些Linux系统没有安装zipinfo命令,可以使用以下命令进行安装:

  • 对于基于Debian的系统,如Ubuntu,可以使用apt-get命令:
[linux@bashcommandnotfound.cn ~]$ sudo apt-get install unzip
  • 对于基于Red Hat的系统,如Fedora,CentOS 7,可以使用yum命令:
[linux@bashcommandnotfound.cn ~]$ sudo yum install unzip
  • 对于CentOS 8,可以使用dnf命令:
[linux@bashcommandnotfound.cn ~]$ sudo dnf install unzip

Linux zipinfo命令的基本语法

zipinfo命令的基本语法如下:

zipinfo [选项] 压缩文件 [文件...] [-x 排除文件...]

其中,压缩文件是要查看的zip文件的路径,可以使用通配符来匹配多个文件。文件是压缩文件中要查看的文件的列表,也可以使用通配符或正则表达式来匹配多个文件。排除文件是压缩文件中要忽略的文件的列表,也可以使用通配符或正则表达式来匹配多个文件。

Linux zipinfo命令的常用选项说明

zipinfo命令的常用选项如下:

选项说明
-1只列出文件名称,每行一个。这个选项排除所有其他选项,不显示头部,尾部和压缩文件的注释。这个选项适用于Unix脚本中。
-2此参数的效果和指定"-1"参数类似,但可搭配"-h","-t"和"-z"参数使用。
-h只列出压缩文件的文件名称。
-l此参数的效果和指定"-m"参数类似,但会列出原始文件的大小而非每个文件的压缩率。
-m此参数的效果和指定"-s"参数类似,但多会列出每个文件的压缩率。
-M若信息内容超过一个画面,则采用类似more指令的方式列出信息。
-s用类似执行ls -l指令的效果列出压缩文件内容。
-t只列出压缩文件内所包含的文件数目,压缩前后的文件大小及压缩率。
-T将压缩文件内每个文件的日期时间用年,月,日,时,分,秒的顺序列出。
-v详细显示压缩文件内每一个文件的信息。
-x不列出符合条件的文件的信息。
-z如果压缩文件内含有注释,就将注释显示出来。

Linux zipinfo命令的实例

以下是一些zipinfo命令的实例:

  • 显示压缩文件的基本信息:
[linux@bashcommandnotfound.cn ~]$ zipinfo test.zip
Archive:  test.zip
Zip file size: 486 bytes, number of entries: 4
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 a.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 b.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 c.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 e.c
4 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
  • 显示压缩文件的详细信息:
[linux@bashcommandnotfound.cn ~]$ zipinfo -v test.zip
Archive:  test.zip
There is no zipfile comment.

End-of-central-directory record:
-------------------------------

  Actual offset of end-of-central-dir record:                 464 (000001D0h)
  Expected offset of end-of-central-dir record:               464 (000001D0h)
  (based on the length of the central directory and its expected offset)

  This zipfile constitutes the sole disk of a single-part archive; its
 ...
  • 只列出压缩文件中的文件名:
[linux@bashcommandnotfound.cn ~]$ zipinfo -1 test.zip
a.c
b.c
c.c
e.c
  • 只列出压缩文件的注释:
[linux@bashcommandnotfound.cn ~]$ zipinfo -z test.zip
This is a test zip file with some comments.
  • 不列出压缩文件中以.c结尾的文件的信息:
[linux@bashcommandnotfound.cn ~]$ zipinfo -x *.c test.zip
Archive:  test.zip
Zip file size: 486 bytes, number of entries: 4
4 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
  • 用类似more指令的方式列出压缩文件的详细信息:
[linux@bashcommandnotfound.cn ~]$ zipinfo -M test.zip
Archive:  test.zip
Zip file size: 486 bytes, number of entries: 4
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 a.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 b.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 c.c
-rw-r--r--  2.3 unx        0 b- stor 10-May-23 18:54 e.c
4 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
--More--(0%)

Linux zipinfo命令的注意事项

  • zipinfo命令只能查看zip格式的压缩文件,不能查看其他格式的压缩文件,如tar.gz, rar等。
  • zipinfo命令不能修改压缩文件的内容,只能查看信息。如果要修改压缩文件的内容,可以使用zip或unzip命令。
  • 如果系统没有安装zipinfo命令,会出现bash: zipinfo: command not found的错误提示,此时可以使用上面提到的方法进行安装。
0

评论区