unzip (在zip归档文件中列出,测试和提取压缩文件)

嚯嚯 发表于 2020-07-25 06:01
浏览次数:
在手机上阅读

在类Unix操作系统,unzip命令列出,提取物和测试压缩的文件,ZIP 压缩文件。 本文档介绍了Linux版本的unzip。

查看英文版

目录

1 unzip 运行系统环境

2 unzip 描述

3 unzip 语法

4 unzip 示例

unzip 运行系统环境

Linux

unzip 描述

unzip将列出,测试或从zip格式的存档中提取文件,而zip格式的存档通常在MS-DOS和Windows系统上找到。 默认行为(不带任何选项)是将指定zip存档中的所有文件提取到当前目录(可能还包括其下的子目录)。 配套程序zip创建zip存档。zipunzip均与PKWARE的PKZIP和PKUNZIP程序为MS-DOS创建的档案兼容。
unzip will list, test, or extract files from archives of the zip format, which are most commonly found on MS-DOS and Windows systems. The default behavior (with no options) is to extract into the current directory (and possibly the subdirectories below it) all files from the specified zip archive. A companion program, zip, creates zip archives. Both zip and unzip are compatible with archives created by PKWARE's PKZIP and PKUNZIP programs for MS-DOS.

查看英文版

查看中文版

unzip 语法

unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] 
      [-x xfile(s) ...] [-d exdir]
参数

unzip遵守以下参数:

file[.zip] zip存档的路径。如果文件规范是通配符,则按照操作系统(或文件系统)确定的顺序处理每个匹配文件。只有文件名可以是通配符。路径本身不能。通配符表达式与常用的Unix shell(sh,ksh,csh)支持的表达式相似,并且可能包含:

* 匹配0个或多个字符的序列
正好匹配1个字符
[ ... ] 与括号内的任何单个字符匹配;范围由开始字符,连字符和结束字符指定。如果感叹号或尖号('  '或' ^ ')紧跟左括号,则括号内的字符范围将得到补充(即,括号内的字符除外)。要指定逐字左括号,必须使用三个字符的序列“ [[] ”。
(请确保引用可能由操作系统解释或修改的任何字符,尤其是在Unix和VMS下。)如果找不到匹配项,则该规范假定为原义文件名;如果仍然失败,则会附加后缀 .zip。请注意,与任何其他zip归档文件一样,支持自解压zip文件。只需显式指定.exe后缀(如果有)。
[file(s)] 待处理的归档成员的可选列表,以空格分隔。(带VMSCLI编译VMS版本中定义必须界定文件用逗号来代替。参见-v在OPTIONS下面。)正则表达式(通配符)可以被用于将多个部件匹配,如上面所述。同样,请确保引用由操作系统扩展或修改的表达式。
-x xfile(s) ] 归档成员的可选列表,将其从处理中排除。由于通配符通常匹配(' / ')目录分隔符(有关例外情况,请参阅选项-W),因此此选项可用于排除子目录中的所有文件。例如,“ unzip foo *。[ch] -x * / * ”将提取主目录中的所有C 源文件,但未提取任何子目录中的C 源文件。如果没有-x选项,则将解压缩zipfile中所有目录中的所有C源文件。
-d exdir ] 如果指定,文件将被提取到目录exdir。默认情况下,所有文件和子目录都在当前目录中创建;所述-d选项允许提取在任意目录(假设总是一个具有允许对写入到目录)。此选项不必出现在命令行末尾;也可以在zipfile规范之前(带有常规选项),在zipfile规范之后,或者在文件和-x选项之间接受它。选项和目录可以串联在一起,而它们之间没有任何空格,但是请注意,这可能会导致正常的shell行为受到抑制。特别是, ”-d〜 “(波浪)是由Unix的C shell扩展到用户名的主目录,但” -d〜 “被视为文字子目录” 当前目录的“。
选项

此外,unzip接受以下选项:

-Z zipinfo模式。如果命令行上的第一个选项是-Z,则其余选项将被视为zipinfo选项。
-一个 [ OS / 2,Unix DLL ]打印扩展的DLL编程接口(API)帮助。
-C 将文件提取到stdout / screen(“ CRT ”)。此选项与-p选项相似,不同之处在于每个文件的名称在提取时都会打印出来,允许使用-a选项,并且在适当的情况下会自动执行ASCII - EBCDIC转换。此选项未在解压缩用法屏幕中列出。
-F 刷新现有文件,即仅提取磁盘上已存在且比磁盘副本新的文件。缺省情况下,在覆盖之前先解压缩 查询,但是-o选项可用于禁止查询。请注意,在许多操作系统下,必须正确设置TZ(时区)环境变量,以使-f-u正常工作(在Unix下,该变量通常是自动设置的)。这样做的原因有些微妙,但与DOS格式的文件时间(总是本地时间)和Unix格式的时间(总是GMT / UTC)之间的差异有关。)以及将两者进行比较的必要性。典型的TZ值是“ PST8PDT ”(美国太平洋时间,可以自动调整夏令时)。
-l 列出存档文件(短格式)。打印指定文件的名称,未压缩的文件大小以及修改日期和时间,以及所有指定文件的总数。如果解压缩使用定义的OS2_EAS进行编译,则-l选项还将列出存储的OS / 2扩展属性(EA)和OS / 2访问控制列表(ACL)大小的列。此外,还会显示zipfile注释和单个文件注释(如果有)。如果文件是从单大小写文件系统(例如,旧的MS-DOS FAT文件系统)中归档的,并且给出了-L选项,则文件名将转换为小写并以脱字符号(^)。
-p 将文件提取到管道(标准输出,标准输出)。除了文件数据外,什么都没有发送到stdout,并且文件总是以二进制格式提取,就像存储文件一样(不进行转换)。
-t 测试存档文件。此选项提取内存中的每个指定文件,并将扩展文件的CRC(循环冗余校验,增强的校验和)与原始文件存储的CRC值进行比较。
-T [大多数操作系统]将存档上的时间戳设置为每个中最新文件的时间戳。这与zip的-go选项相对应,不同之处在于它可以用于通配符zip文件(例如,“ unzip -T \ *。zip ”),并且速度更快。
-u 更新现有文件并根据需要创建新文件。该选项执行与-f选项相同的功能,提取(带有查询)比磁盘上具有相同名称的文件新的文件,此外,它还提取磁盘上不存在的文件。有关正确设置时区的信息,请参见上面的-f
-v 列出存档文件(详细格式)或显示诊断版本信息。此选项已发展,现在既充当选项又充当修饰符。作为一个选项,它有两个用途:当指定一个zipfile且没有其他选项时,-v详细列出归档文件,在基本-l info中添加压缩方法,压缩大小,压缩率和32位CRC。与大多数竞争性实用程序相比,解压缩可删除加密的12个附加头字节字节压缩大小数字中的条目。因此,压缩大小和压缩率数字与条目的加密状态无关,并显示正确的压缩性能。(用于zipfile条目的加密压缩数据流的完整大小由更详细的zipinfo报告来报告。)未指定zipfile时(即,完整命令为“ unzip -v ”),将显示诊断屏幕。除了带有发布日期和版本的普通标题外,还需解压缩列出家庭Info-ZIP ftp站点以及在哪里可以找到其他ftp和非ftp站点的列表;对其进行编译的目标操作系统,以及(可能)在其上进行编译的硬件,所使用的编译器和版本以及编译日期;任何可能影响程序操作的特殊编译选项(另请参见下面的DECRYPTION);以及存储在环境变量中的任何可能执行相同操作的选项(请参阅下面的“ 环境选项”)。作为修饰符,它可以与其他选项(例如-t)结合使用,以产生更多详细信息或调试输出。
-z 仅显示存档注释。
修饰符
-a 转换文本文件。通常,所有文件都完全按照其存储方式提取(作为“二进制”文件)。所述-a选项使通过拉链为文本文件(那些与“识别的文件在”标签zipinfo列表,而不是“ b ”),以作为这样的自动提取,转换行结束,结束文件的字符和字符根据需要进行设置。(例如,Unix文件使用换行符(LF)作为行尾(EOL)且没有文件结束(EOF)标记;Macintosh使用EOL的回车(CR);以及大多数PC操作系统使用CR + LF用于EOL,而Control-Z用于EOF。另外,IBM 大型机和密歇根州终端系统使用EBCDIC而不是更常见的ASCII字符集,而NT支持Unicode。)请注意,zip对文本文件的识别绝不是完美的;一些“文本”文件实际上可能是二进制文件,反之亦然。因此,对于使用-a选项提取的每个文件,unzip会打印“ [text] ”或“ [binary] ”作为对其进行目测的检查。该-AA选项强制所有文件中提取文本,无论是所谓的文件类型。在VMS上,另请参阅-S
-b [general]将所有文件视为二进制文件(不进行文本转换)。这是--- a的快捷方式。
-b [Tandem] 在提取标记为“文本”的Zip条目时强制使用文件代码类型180(' C ')的创建文件。(在串联时,-a默认情况下处于启用状态;请参见上文)。
-b [VMS]自动将二进制文件(请参见上面的-a)转换为固定长度的512 字节记录格式。将选项(-bb)加倍会使所有文件以这种格式提取。提取到标准输出时(实际上是-c-p选项),对于二进制(-b)响应,将禁用文本记录定界符的默认转换。所有(-bb)文件。
-B [使用定义的UNIXBACKUP进行编译时]保存每个覆盖文件的备份副本。备份文件将获取目标文件的名称,并带有波浪号和可选的唯一序列号(最多5 位)。只要已经存在具有原始名称加代字号的另一个文件,就应用序列号。与“全部覆盖”选项-o一起使用时,永远不会创建编号的备份文件。在这种情况下,所有备份文件都将被命名为带有附加波浪号的原始文件,现有的备份文件将被删除,恕不另行通知。此功能与许多位置的emacs的默认行为类似。

例如,将“ foo ” 的旧副本重命名为“ foo〜 ”。

:警告:用户应注意-B选项不能在所有情况下都防止丢失现有数据。例如,当以全写模式运行unzip时,将在尝试进行解压缩之前删除现有的“ foo〜 ”文件。将“ foo ” 重命名为“ foo〜 ”。如果重命名尝试失败(由于文件锁定,权限不足或其他原因),“ foo〜 ” 的提取将被取消,但是旧的备份文件已经丢失。当编号备份文件的序列号范围用尽(9999965535(对于16位)系统)。在这种情况下,具有最大序列号的备份文件将被删除,并由新的备份版本替换,恕不另行通知。
-C 使用不区分大小写的匹配从提取选择模式的命令行列表中选择归档条目。unzip的理念是“满足您的要求”(这还负责-L / -U更改;请参见下面的相关选项)。由于某些文件系统完全区分大小写(特别是在Unix操作系统下),并且zip存档和unzip本身都可以跨平台移植,因此unzip的默认行为是区分大小写匹配通配符和文本文件名。也就是说,在命令行上指定“ makefile ”将仅与归档文件中的“ makefile ”匹配,而不与“MAKEFILE “(以及类似的通配符规范)。由于这与许多其他操作系统/文件系统(例如OS / 2 HPFS,它保留大小写但不区分大小写)的行为不符,因此-C选项在上面的示例中,所有三个文件都将匹配“ makefile ”(或“ make * ” 或类似名称)。在-C选项会影响正常的文件列表和排除文件列表(包括文件规范的Xlist)。

请注意-C选项不会影响对zip文件的搜索,也不会影响存档条目与提取路径上现有文件的匹配。在区分大小写的文件系统上,解压缩将永远不会在提取条目“ foo ” 时尝试覆盖文件“ FOO ”!
-D 跳过提取项目时间戳的恢复。通常,解压缩会尝试恢复Zip存档中提供的提取项目的所有元信息(并且不需要特权或不会带来安全风险)。通过指定-D,告诉unzip禁止恢复从Zip存档条目显式创建的目录的时间戳。此选项仅适用于支持设置目录时间戳的端口(当前为ATheOS,BeOS,MacOS,OS / 2,Unix,VMS,Win32;对于其他解压缩端口,-D无效)。复制的选项-DD强制抑制所有提取的条目(文件和目录)的时间戳恢复。此选项导致将所有提取的条目的时间戳设置为当前时间。

在VMS上,此选项的默认设置为-D,以与BACKUP的行为保持一致:恢复文件时间戳记,在当前时间保留提取目录的时间戳记。要恢复目录时间戳,应指定否定的选项--D。在VMS上,选项-D禁用所有提取的Zip存档项目的时间戳恢复。(这里,命令行上的单个-D与默认的-D结合起来可以执行显式-DD 在其他系统上执行。)
-E [仅适用于MacOS ] 在还原操作期间显示MacOS Extra字段的内容。
-F [仅橡子]禁止从存储的文件名中删除NFS文件类型扩展名。
-F [非Acorn系统支持带有嵌入式逗号的长文件名,并且仅当使用ACORN_FTYPE_NFS定义时才进行编译]将来自ACORN RISC OS额外字段块的文件类型信息转换为NFS文件类型扩展名并将其附加到提取文件的名称中。(当存储的文件名看起来已经具有附加的NFS文件类型扩展名时,它将被多余字段中的信息替换。)
-i [仅适用于MacOS]忽略MacOS额外字段中存储的文件名。而是使用存储在条目标题的通用部分中的最兼容文件名。
-j 垃圾路径。不会重新创建档案的目录结构;所有文件都存放在提取目录中(默认情况下是当前目录)。
-J [仅适用于BeOS]垃圾文件属性。文件的BeOS文件属性不会恢复,仅文件的数据会恢复。
-J [仅MacOS]忽略MacOS额外字段。跳过所有Macintosh特定信息。数据叉和资源叉将作为单独的文件还原。
-K [仅AtheOS,BeOS,Unix)保留SUID / SGID / Tacky 文件属性。没有此标志,出于安全原因,将清除这些属性位。
-L 将源自仅大写的操作系统或文件系统的任何文件名转换为小写。(这是5.11之前的发行版中unzip的默认行为;新的默认行为与带有-U选项的旧行为相同,该行为现在已过时,将在以后的版本中删除。)根据存档程序,在以下位置存档的文件单例文件系统(VMS,旧的MS-DOS FAT等)可以存储为全大写名称;当提取到一个保留大小写的文件系统(例如OS / 2 HPFS)或区分大小写的文件系统(例如在Unix下)时,这可能很丑陋或不便。默认情况下,解压缩会列出并提取与存储完全相同的文件名(截断除外),不支持的字符的转换等);此选项导致某些系统中所有文件的名称都转换为小写。该-LL每一个文件名的选项将强制转换为小写,无论原始文件系统。
-M 通过类似于Unix more命令的内部寻呼机将所有输出通过管道传输。在屏幕显示的最后,解压缩暂停,并显示“ --More-- ” 提示;通过按Enter(返回)键或空格键可以查看下一屏。可以通过按“ q ”键以及在某些系统上按Enter / Return键终止解压缩。与Unix more不同,它没有前向搜索或编辑功能。另外,解压缩不会注意到是否在屏幕边缘缠绕了长行,从而有效地导致打印了两行或更多行,以及某些文本在被查看之前从屏幕顶部滚动的可能性。在某些系统上,未检测到屏幕上可用的行数,在这种情况下,解压缩假定高度为24行。
-n 永远不会覆盖现有文件。如果文件已经存在,请跳过该文件的提取而无需提示。默认情况下,在解压缩任何存在的文件之前先解压缩查询;用户可以选择仅覆盖当前文件,覆盖所有文件,跳过当前文件的提取,跳过所有现有文件的提取或重命名当前文件。
-N [ Amiga ]提取文件注释为Amiga文件注释。文件注释与创建-c的选项拉链,或与-N的Amiga的端口选项拉链,其门店filenotes为注释。
-o 覆盖现有文件而无提示。这是一个危险的选择,因此请谨慎使用。(但是,它通常与-f一起使用,并且是覆盖OS / 2下目录EA的唯一方法。)
-P password 使用密码来解密加密的压缩文件条目(如果有的话)。这是不安全的!许多多用户操作系统为任何用户提供了查看其他任何用户的当前命令行的方法。即使在独立系统上,也始终存在过度偷看的威胁。将纯文本密码作为命令行的一部分存储在自动化脚本中的情况更加糟糕。尽可能使用无回声的交互式提示输入密码。(在真正重要的安全性方面,请使用强加密(例如,Pretty Good Privacy),而不要使用标准zipfile实用程序提供的相对弱的加密。)
-q 安静地执行操作(-qq =更加安静)。通常,解压缩会打印要提取或测试的文件的名称,提取方法,可能存储在归档文件中的任何文件或zipfile注释,以及在完成每个归档文件时的摘要。所述-q [ q ]选项抑制的一些或所有这些消息的打印。
-s [OS / 2,NT,MS-DOS]将文件名中的空格转换为下划线。由于所有PC操作系统都在文件名中允许使用空格,因此默认情况下,解压缩会提取完整的文件名(例如,“ EA DATA。SF ”)。但是,这可能很尴尬,因为特别是MS-DOS并不优雅地支持文件名中的空格。在某些情况下,将空格转换为下划线可以消除尴尬。
-S [VMS]将文本文件(-a-aa)转换为Stream_LF记录格式,而不是文本文件默认的可变长度记录格式。(Stream_LF是VMS 解压缩的默认记录格式。除非请求转换(-a-aa和/或-b-bb)或处理特定于VMS的条目,否则它将应用。
-U [仅UNICODE_SUPPORT]修改或禁用UTF-8处理。当UNICODE_SUPPORT可用时,选项-U强制解压缩以将UTF-8编码文件名中的所有非ASCII字符转义为“ #Uxxxx ”(对于UCS-2字符,对于 “ Unicode代码点需要3 个八位字节 ” 则为 “ #Lxxxxxx ” )。当怀疑是相当新的UTF-8支持会破坏提取的文件名时,主要提供此选项用于调试。

选项-UU允许完全禁用UTF-8编码文件名的识别。解压缩文件名编码的方式可追溯到先前版本的行为。

[旧的,过时的用法]如果在MS-DOS,VMS等环境下创建文件名,则将其大写。请参见上面的-L
-V 保留(VMS)文件版本号。VMS文件可以使用版本号存储,格式为file.ext; ##。默认情况下,将删除“ ; ## ”版本号,但是此选项允许保留它们。(在将文件名限制为特别短的文件系统上,无论使用此选项如何,版本号都可能被截断或剥离。)
-W [仅当启用WILD_STOP_AT_DIR编译时选项时]修改模式匹配例程,以便两个' '(单字符通配符)和' * '(多字符通配符)与目录分隔符' / ' 不匹配。(两个字符的序列“ ** ”用作多字符通配符,在其匹配字符中包括目录分隔符。)示例:

  • “ * .c ”匹配“ foo.c ”,但不匹配“ mydir / foo.c ”
  • “ **。c ”匹配“ foo.c ”和“ mydir / foo.c ”
  • “ * / *。c ”匹配“ bar / foo.c ”但不匹配“ baz / bar / foo.c ”
  • “ ?? * / * ”匹配“ ab / foo ”和“ abc / foo ”,但不匹配“ / foo ”或“ a / b / foo ”
修改后的行为等同于UnZip的某些受支持目标OS(例如Acorn RISC OS)的外壳所使用的模式匹配样式。在本地操作系统文件名中允许将Zip存档的内部目录分隔符' / '用作常规字符的系统上,此选项可能不可用。(当前,在大多数端口中,unzip对通配符zipfile规范和zip条目选择模式使用相同的模式匹配规则。对于允许` / '作为常规文件名字符的系统,-W选项在通配符zipfile规范中无法正常工作。 )
-X [VMS,Unix,OS / 2,NT,Tandem] 在VMS下还原所有者/保护信息(UIC和ACL条目),在Unix下还原用户和组信息(UID / GID),或在某些网络下还原访问控制列表(ACL)的OS / 2版本(带有IBM LAN Server / Requester 3.0到5.0的Warp Server;带有IBM Peer 1.0的Warp Connect)或Windows NT下的安全ACL。在大多数情况下,这将需要特殊的系统特权,并且将NT下的选项(-XX)加倍会指示解压缩使用特权进行提取;但是例如,在Unix下,属于多个组的用户可以恢复这些组中任何一个拥有的文件,只要用户ID与自己的ID匹配即可。请注意,普通文件属性始终会还原-此选项仅适用于某些操作系统上可用的可选的额外所有权信息。[NT的访问控制列表似乎与OS / 2并不特别兼容,因此没有尝试跨平台的访问权限可移植性。]
-Y [VMS]将已归档文件名的结尾“ .nnn ”(其中“ nnn ”是十进制数字)视为它们是VMS版本号(“ ; nnn ”)。(默认是将它们视为文件类型。)例如:“ ab3 ”->“ ab; 3 ”。
-$ 如果提取介质是可移动的(例如软盘),则[MS-DOS,OS / 2,NT]将恢复卷标。将选项(-$$)加倍也可以标记固定媒体(硬盘)。默认情况下,将忽略卷标。
-/ extension [仅橡子]覆盖由Unzip $ Ext环境变量提供的扩展名列表。在提取过程中,与该扩展名列表中的一项匹配的文件扩展名会在提取文件的基本名称前交换。
-: [除了Acorn,VM / CMS,MVS,Tandem以外的所有文件]允许将存档成员提取到当前“提取根文件夹”之外的位置。出于安全原因,解压缩通常会从提取文件的名称中删除“父目录”路径组件(“ ../ ”)。此安全功能(版本5.50的新增功能)可防止解压缩意外将文件写入活动提取文件夹树头外部的“敏感”区域。使用-:选项可将其解压缩,以切换回其先前的更自由的行为,以允许准确提取使用“ ../“组件可在当前提取文件夹级别创建多个目录树。此选项无法将其显式写入根目录(” / “)。要实现此目的,必须将提取目标文件夹设置为root(例如,-d /)。但是,当指定-:选项时,仍然可以通过在zip归档文件中指定足够的“ ../ ”路径组件来隐式写入根目录。请格外小心。
-^ [仅限于Unix]允许在提取的zip归档条目的名称中包含控制字符。在Unix上,文件名可以包含任何(8位)字符代码,但带有两个例外' / '(目录定界符)和NUL(0x00(C字符串终止指示符),除非特定文件系统具有更多限制性约定。通常,至少在“本地” Unix文件系统上,这允许将ASCII控制字符(甚至复杂的控制序列)嵌入文件名中。但是,利用此Unix的“功能”可能非常可疑。当文件名中嵌入的控制字符在某些列表代码中在屏幕上显示时,如果没有足够的过滤,可能会带来讨厌的副作用。并且,对于普通用户而言,可能难以处理此类文件名(例如,当尝试为打开,复制,移动或删除操作指定文件名时)。因此,默认情况下,unzip应用一个过滤器,该过滤器从提取的文件名中删除潜在危险的控制字符。本- ^ 选项允许在有意恢复嵌入的文件名控制字符的极少数情况下覆盖此过滤器。
-2 [VMS]强制将文件名无条件转换为ODS2兼容名称。默认设置是利用目标文件系统,在ODS5目标文件系统上保留大小写和扩展文件名字符;在ODS2目标文件系统上应用ODS2兼容性文件名过滤。
选项

可以通过放置在环境变量中的选项来修改unzip的默认行为。可以使用任何选项来完成此操作,但是使用-a-L-C-q-o-n修饰符可能最有用:默认情况下使unzip自动转换文本文件,使其转换为文件名从大写到小写,使其不区分大小写匹配名称,使其更安静,或者在提取文件时始终覆盖或从不覆盖文件。例如,要使解压缩尽可能安静地执行,仅报告错误,可以使用以下命令之一:

Unix Bourne shell:

UNZIP = -qq; 出口UNZIP

Unix C shell:

setenv UNZIP -qq

OS / 2或MS-DOS:

set UNZIP = -qq

VMS(小写报价):

define UNZIP_OPTS“ -qq”

实际上,环境选项被认为与任何其他命令行选项一样,只是它们实际上是命令行上的第一个选项。要覆盖环境选项,可以使用“减号运算符”将其删除。例如,要覆盖上面示例中的静默标志之一,请使用以下命令。

unzip--q [other options] zipfile

第一个连字符是普通开关字符,第二个是减号,作用于q选项。因此,这里的作用是消除一种安静。要取消两个安静标志,可以使用两个(或更多)负号:

unzip -t--q zipfile
unzip ---qt zipfile

(两者是等效的)。这可能看起来很尴尬或令人困惑,但它相当直观:只需忽略第一个连字符并从那里开始。这也与Unix nice的行为一致。

如上面的示例所建议,对于VMS ,默认变量名称是UNZIP_OPTS(否则,用于将unzip作为外部命令安装的符号将与环境变量混淆),对于所有其他操作系统,则为UNZIP。对于兼容性拉链UNZIPOPT是可以接受的。但是,如果同时定义了UNZIPUNZIPOPT,则UNZIP优先。unzip的诊断选项(-v,不带zipfile名称)可用于检查所有四个可能的unzip和zipinfo环境变量的值。

应根据本地时区设置时区变量(TZ),以使-f-u正常运行。有关详细信息,请参见上面对-f的描述。要正确设置提取文件的时间戳,可能还需要使用此变量。假设已在“ 控制面板”中正确设置了解压缩的WIN32(Win9x / ME / NT4 / 2K / XP / 2K3)端口,则可从注册表获取时区配置。该端口的TZ变量被忽略。

解密

Info-ZIP软件完全支持加密的存档,但是由于美国的出口限制,可能在您特定的编译二进制文件中禁用了解密/加密支持。但是,自2000年春季以来,美国的出口限制已被解除,我们的原始档案现在确实包含完整的密码。如果您需要启用了crypt支持的二进制发行版,请在任何Info-ZIP源或二进制发行版中查看文件“ WHERE ”,以获取美国境内和境外的位置。

某些解压缩的编译版本可能不支持解密。要检查版本是否支持crypt,请尝试测试或提取加密的归档文件,或者检查unzip的诊断屏幕(请参见上面的-v选项),以将“ [decryption] ”作为特殊的编译选项之一。

如上所述,-P选项可用于在命令行上提供密码,但是会增加安全性。首选的解密方法是正常提取。如果zipfile成员已加密,则unzip将提示您输入密码,而不回显键入的内容。只要测试12字节的标头,unzip就会继续使用相同的密码(只要它看起来有效)在每个文件上。正确的密码将始终根据标题检出,但是不正确的密码也有1-in-256的机会。(这是PKWARE zipfile格式的安全功能;它有助于防止蛮力攻击,否则仅通过测试标头就可以获得较大的速度优势。)如果输入了错误的密码,但无论如何它都会通过标头测试,将为提取的数据生成错误的CRC,或者在提取过程中解压缩失败,因为“已解密”字节不构成有效的压缩数据流。

如果第一个密码未能通过文件头检查,则解压缩将提示输入另一个密码,依此类推,直到提取所有文件为止。如果密码未知,则将输入空密码(即,仅输入回车或“ Enter”)作为跳过所有进一步提示的信号。此后,仅提取存档中未加密的文件。(实际上,事实并非如此;较早版本的zipzipcloak允许使用空密码,因此,unzip检查每个加密文件以查看空密码是否有效。如上所述,这可能会导致“误报”和提取错误。)

用8位密码加密的档案(例如带有重音符号的欧洲字符的密码)可能无法在系统和/或其他档案中移植。此问题源于对此类字符使用了多种编码方法,包括Latin-1(ISO 8859-1)和OEM代码页850。DOSPKZIP 2.04g使用OEM代码页;而PKZIP 2.04g使用OEM代码页。Windows PKZIP 2.50使用Latin-1(因此与DOS PKZIP不兼容);Info-ZIP在DOS,OS / 2和Win3.x端口上使用OEM代码页,但在其他任何地方都使用ISO编码(Latin-1等)。Nico Mak的WinZip 6.x根本不允许8位密码。解压缩5.3(或更高版本)尝试首先使用默认字符集(例如Latin-1),然后使用替代字符集(例如OEM代码页)来测试密码。在EBCDIC系统上,如果这两种方法均失败,则将对EBCDIC编码进行最后测试。(由于没有已知的使用EBCDIC编码进行加密的存档器,因此未在非EBCDIC系统上进行EBCDIC的测试。)不支持Latin-1以外的ISO字符编码。UnZip 6.0中新增的(部分)Unicode(分别为UTF-8)支持尚未适应unzip中的加密密码处理。在使用UTF-8作为本机字符编码的系统上,解压缩尝试使用本地UTF-8编码密码解密;内置的尝试以翻译编码检查密码的尝试尚未适应UTF-8支持,因此将失败。

unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] 
      [-x xfile(s) ...] [-d exdir]
Arguments

unzip accepts the following arguments:

file[.zip] Path of the zip archive(s). If the file specification is a wildcard, each matching file is processed in an order determined by the operating system (or file system). Only the filename can be a wildcard; the path itself cannot. Wildcard expressions are similar to those supported in commonly used Unix shells (sh, ksh, csh) and may contain:

* matches a sequence of 0 or more characters
? matches exactly 1 character
[...] matches any single character found inside the brackets; ranges are specified by a beginning character, a hyphen, and an ending character. If an exclamation point or a caret ('!' or '^') follows the left bracket, then the range of characters within the brackets is complemented (that is, anything except the characters inside the brackets is considered a match). To specify a verbatim left bracket, the three-character sequence "[[]" has to be used.
(Be sure to quote any character that might otherwise be interpreted or modified by the operating system, particularly under Unix and VMS.) If no matches are found, the specification is assumed to be a literal filename; and if that also fails, the suffix .zip is appended. Note that self-extracting zip files are supported, as with any other zip archive; just specify the .exe suffix (if any) explicitly.
[file(s)] An optional list of archive members to be processed, separated by spaces. (VMS versions compiled with VMSCLI defined must delimit files with commas instead. See -v in OPTIONS below.) Regular expressions (wildcards) may be used to match multiple members, as stated above. Again, be sure to quote expressions that would otherwise be expanded or modified by the operating system.
[-x xfile(s)] An optional list of archive members to be excluded from processing. Since wildcard characters normally match ('/') directory separators (for exceptions see the option -W), this option may be used to exclude any files that are in subdirectories. For example, "unzip foo *.[ch] -x */*" would extract all C source files in the main directory, but none in any subdirectories. Without the -x option, all C source files in all directories within the zipfile would be extracted.
[-d exdir] If specified, files will be extracted to directory exdir. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not appear at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed. In particular, "-d ~" (tilde) is expanded by Unix C shells into the name of the user's home directory, but "-d~" is treated as a literal subdirectory "~" of the current directory.
Options

Additionally, unzip accepts the following options:

-Z zipinfo mode. If the first option on the command line is -Z, the remaining options are taken to be zipinfo options.
-A [OS/2, Unix DLL] print extended help for the DLL's programming interface (API).
-c extract files to stdout/screen ("the CRT"). This option is similar to the -p option except that the name of each file is printed as it is extracted, the -a option is allowed, and ASCII-EBCDIC conversion is automatically performed if appropriate. This option is not listed in the unzip usage screen.
-f freshen existing files, i.e., extract only those files that already exist on disk and that are newer than the disk copies. By default, unzip queries before overwriting, but the -o option may be used to suppress the queries. Note that under many operating systems, the TZ (timezone) environment variable must be set correctly for -f and -u to work properly (under Unix the variable is usually set automatically). The reasons for this are somewhat subtle but have to do with the differences between DOS-format file times (always local time) and Unix-format times (always in GMT/UTC) and the necessity to compare the two. A typical TZ value is "PST8PDT" (US Pacific time with automatic adjustment for Daylight Savings Time).
-l list archive files (short format). The names, uncompressed file sizes and modification dates and times of the specified files are printed, along with totals for all files specified. If unzip was compiled with OS2_EAS defined, the -l option also lists columns for the sizes of stored OS/2 extended attributes (EAs) and OS/2 access control lists (ACLs). Also, the zipfile comment and individual file comments (if any) are displayed. If a file was archived from a single-case file system (for example, the old MS-DOS FAT file system) and the -L option was given, the filename is converted to lowercase and is prefixed with a caret (^).
-p extract files to pipe (standard output, stdout). Nothing but the file data is sent to stdout, and the files are always extracted in binary format, just as they are stored (no conversions).
-t test archive files. This option extracts each specified file in memory and compares the CRC (cyclic redundancy check, an enhanced checksum) of the expanded file with the original file's stored CRC value.
-T [most OSes] set the timestamp on the archive(s) to that of the newest file in each one. This corresponds to zip's -go option except that it can be used on wildcard zipfiles (e.g., "unzip -T \*.zip") and is much faster.
-u update existing files and create new ones if needed. This option performs the same function as the -f option, extracting (with query) files that are newer than those with the same name on disk, and in addition it extracts those files that do not already exist on disk. See -f above for information on setting the timezone properly.
-v list archive files (verbose format) or show diagnostic version info. This option has evolved and now behaves as both an option and a modifier. As an option it has two purposes: when a zipfile is specified with no other options, -v lists archive files verbosely, adding to the basic -l info the compression method, compressed size, compression ratio and 32-bit CRC. In contrast to most of the competing utilities, unzip removes the 12 additional header bytes of encrypted entries from the compressed size numbers. Therefore, compressed size and compression ratio figures are independent of the entry's encryption status and show the correct compression performance. (The complete size of the encrypted compressed data stream for zipfile entries is reported by the more verbose zipinfo reports.) When no zipfile is specified (that is, the complete command is "unzip -v"), a diagnostic screen is printed. In addition to the normal header with release date and version, unzip lists the home Info-ZIP ftp site and where to find a list of other ftp and non-ftp sites; the target operating system for which it was compiled, as well as (possibly) the hardware on which it was compiled, the compiler and version used, and the compilation date; any special compilation options that might affect the program's operation (see also DECRYPTION below); and any options stored in environment variables that might do the same (see ENVIRONMENT OPTIONS below). As a modifier it works in conjunction with other options (e.g., -t) to produce more verbose or debugging output.
-z display only the archive comment.
Modifiers
-a convert text files. Ordinarily all files are extracted exactly as they are stored (as "binary" files). The -a option causes files identified by zip as text files (those with the 't' label in zipinfo listings, rather than 'b') to be automatically extracted as such, converting line endings, end-of-file characters and the character set itself as necessary. (For example, Unix files use line feeds (LFs) for end-of-line (EOL) and have no end-of-file (EOF) marker; Macintoshes use carriage returns (CRs) for EOLs; and most PC operating systems use CR+LF for EOLs and control-Z for EOF. Also, IBM mainframes and the Michigan Terminal System use EBCDIC rather than the more common ASCII character set, and NT supports Unicode.) Note that zip's identification of text files is by no means perfect; some "text" files may actually be binary and vice versa. unzip therefore prints "[text]" or "[binary]" as a visual check for each file it extracts when using the -a option. The -aa option forces all files to be extracted as text, regardless of the supposed file type. On VMS, see also -S
-b [general] treat all files as binary (no text conversions). This is a shortcut for ---a.
-b [Tandem] force the creation files with file code type 180 ('C') when extracting Zip entries marked as "text". (On Tandem, -a is enabled by default; see above).
-b [VMS] auto-convert binary files (see -a above) to fixed-length, 512-byte record format. Doubling the option (-bb) forces all files to be extracted in this format. When extracting to standard output (-c or -p option in effect), the default conversion of text record delimiters is disabled for binary (-b) resp. all (-bb) files.
-B [when compiled with UNIXBACKUP defined] save a backup copy of each overwritten file. The backup file is gets the name of the target file with a tilde and optionally a unique sequence number (up to 5 digits) appended. The sequence number is applied whenever another file with the original name plus tilde already exists. When used together with the "overwrite all" option -o, numbered backup files are never created. In this case, all backup files are named as the original file with an appended tilde, existing backup files are deleted without notice. This feature works similarly to the default behavior of emacs in many locations.

As an example, an old copy of "foo" is renamed to "foo~".

Warning: Users should be aware that the -B option does not prevent loss of existing data under all circumstances. For example, when unzip is run in overwrite-all mode, an existing "foo~" file is deleted before unzip attempts to rename "foo" to "foo~". When this rename attempt fails (because of a file locks, insufficient privileges, or whatever), the extraction of "foo~" gets cancelled, but the old backup file is already lost. A similar scenario takes place when the sequence number range for numbered backup files gets exhausted (99999, or 65535 for 16-bit systems). In this case, the backup file with the maximum sequence number is deleted and replaced by the new backup version without notice.
-C use case-insensitive matching for the selection of archive entries from the command-line list of extract selection patterns. unzip's philosophy is "you get what you ask for" (this is also responsible for the -L/-U change; see the relevant options below). Because some file systems are fully case-sensitive (notably those under the Unix operating system) and because both zip archives and unzip itself are portable across platforms, unzip's default behavior is to match both wildcard and literal filenames case-sensitively. That is, specifying "makefile" on the command line will only match "makefile in the archive, not "Makefile" or "MAKEFILE" (and similarly for wildcard specifications). Since this does not correspond to the behavior of many other operating/file systems (for example, OS/2 HPFS, which preserves mixed case but is not sensitive to it), the -C option may be used to force all filename matches to be case-insensitive. In the example above, all three files would then match "makefile" (or "make*, or similar). The -C option affects file specs in both the normal file list and the excluded-file list (xlist).

Please note that the -C option does neither affect the search for the zipfile(s) nor the matching of archive entries to existing files on the extraction path. On a case-sensitive file system, unzip will never try to overwrite a file "FOO" when extracting an entry "foo"!
-D skip restoration of timestamps for extracted items. Normally, unzip tries to restore all meta-information for extracted items that are supplied in the Zip archive (and do not require privileges or impose a security risk). By specifying -D, unzip is told to suppress restoration of timestamps for directories explicitly created from Zip archive entries. This option only applies to ports that support setting timestamps for directories (currently ATheOS, BeOS, MacOS, OS/2, Unix, VMS, Win32; for other unzip ports, -D has no effect). The duplicated option -DD forces suppression of timestamp restoration for all extracted entries (files and directories). This option results in setting the timestamps for all extracted entries to the current time.

On VMS, the default setting for this option is -D for consistency with the behaviour of BACKUP: file timestamps are restored, timestamps of extracted directories are left at the current time. To enable restoration of directory timestamps, the negated option --D should be specified. On VMS, the option -D disables timestamp restoration for all extracted Zip archive items. (Here, a single -D on the command line combines with the default -D to do what an explicit -DD does on other systems.)
-E [MacOS only] display contents of MacOS extra field during restore operation.
-F [Acorn only] suppress removal of NFS filetype extension from stored filenames.
-F [non-Acorn systems supporting long filenames with embedded commas, and only if compiled with ACORN_FTYPE_NFS defined] translate filetype information from ACORN RISC OS extra field blocks into an NFS filetype extension and append it to the names of the extracted files. (When the stored filename appears to already have an appended NFS filetype extension, it is replaced by the info from the extra field.)
-i [MacOS only] ignore filenames stored in MacOS extra fields. Instead, the most compatible filename stored in the generic part of the entry's header is used.
-j junk paths. The archive's directory structure is not recreated; all files are deposited in the extraction directory (by default, the current one).
-J [BeOS only] junk file attributes. The file's BeOS file attributes are not restored, just the file's data.
-J [MacOS only] ignore MacOS extra fields. All Macintosh specific info is skipped. Data-fork and resource-fork are restored as separate files.
-K [AtheOS, BeOS, Unix only] retain SUID/SGID/Tacky file attributes. Without this flag, these attribute bits are cleared for security reasons.
-L convert to lowercase any filename originating on an uppercase-only operating system or file system. (This was unzip's default behavior in releases prior to 5.11; the new default behavior is identical to the old behavior with the -U option, which is now obsolete and will be removed in a future release.) Depending on the archiver, files archived under single-case file systems (VMS, old MS-DOS FAT, etc.) may be stored as all-uppercase names; this can be ugly or inconvenient when extracting to a case-preserving file system such as OS/2 HPFS or a case-sensitive one such as under Unix. By default, unzip lists and extracts such filenames exactly as they're stored (excepting truncation, conversion of unsupported characters, etc.); this option causes the names of all files from certain systems to be converted to lowercase. The -LL option forces conversion of every filename to lowercase, regardless of the originating file system.
-M pipe all output through an internal pager similar to the Unix more command. At the end of a screenful of output, unzip pauses with a "--More--" prompt; the next screenful may be viewed by pressing the Enter (Return) key or the spacebar. unzip can be terminated by pressing the "q" key and, on some systems, the Enter/Return key. Unlike Unix more, there is no forward-searching or editing capability. Also, unzip doesn't notice if long lines wrap at the edge of the screen, effectively resulting in the printing of two or more lines and the likelihood that some text will scroll off the top of the screen before being viewed. On some systems the number of available lines on the screen is not detected, in which case unzip assumes the height is 24 lines.
-n never overwrite existing files. If a file already exists, skip the extraction of that file without prompting. By default, unzip queries before extracting any file that already exists; the user may choose to overwrite only the current file, overwrite all files, skip extraction of the current file, skip extraction of all existing files, or rename the current file.
-N [Amiga] extract file comments as Amiga filenotes. File comments are created with the -c option of zip, or with the -N option of the Amiga port of zip, which stores filenotes as comments.
-o overwrite existing files without prompting. This is a dangerous option, so use it with care. (It is often used with -f, however, and is the only way to overwrite directory EAs under OS/2.)
-P password use password to decrypt encrypted zipfile entries (if any). THIS IS INSECURE! Many multi-user operating systems provide ways for any user to see the current command line of any other user; even on stand-alone systems there is always the threat of over-the-shoulder peeking. Storing the plaintext password as part of a command line in an automated script is even worse. Whenever possible, use the non-echoing, interactive prompt to enter passwords. (And where security is truly important, use strong encryption such as Pretty Good Privacy instead of the relatively weak encryption provided by standard zipfile utilities.)
-q perform operations quietly (-qq = even quieter). Ordinarily unzip prints the names of the files it's extracting or testing, the extraction methods, any file or zipfile comments that may be stored in the archive, and possibly a summary when finished with each archive. The -q[q] options suppress the printing of some or all of these messages.
-s [OS/2, NT, MS-DOS] convert spaces in filenames to underscores. Since all PC operating systems allow spaces in filenames, unzip by default extracts filenames with spaces intact (e.g., "EA DATA. SF"). This can be awkward, however, since MS-DOS in particular does not gracefully support spaces in filenames. Conversion of spaces to underscores can eliminate the awkwardness in some cases.
-S [VMS] convert text files (-a-aa) into Stream_LF record format, instead of the text-file default, variable-length record format. (Stream_LF is the default record format of VMS unzip. It is applied unless conversion (-a-aa and/or -b-bb) is requested or a VMS-specific entry is processed.)
-U [UNICODE_SUPPORT only] modify or disable UTF-8 handling. When UNICODE_SUPPORT is available, the option -U forces unzip to escape all non-ASCII characters from UTF-8 coded filenames as "#Uxxxx" (for UCS-2 characters, or "#Lxxxxxx" for unicode codepoints needing 3 octets). This option is mainly provided for debugging purpose when the fairly new UTF-8 support is suspected to mangle up extracted filenames.

The option -UU allows to entirely disable the recognition of UTF-8 encoded filenames. The handling of filename codings within unzip falls back to the behaviour of previous versions.

[old, obsolete usage] leave filenames uppercase if created under MS-DOS, VMS, etc. See -L above.
-V retain (VMS) file version numbers. VMS files can be stored with a version number, in the format file.ext;##. By default, the ";##" version numbers are stripped, but this option allows them to be retained. (On file systems that limit filenames to particularly short lengths, the version numbers may be truncated or stripped regardless of this option.)
-W [only when WILD_STOP_AT_DIR compile-time option enabled] modifies the pattern matching routine so that both '?' (single-char wildcard) and '*' (multi-char wildcard) do not match the directory separator character '/'. (The two-character sequence "**" acts as a multi-char wildcard that includes the directory separator in its matched characters.) Examples:

  • "*.c" matches "foo.c" but not "mydir/foo.c"
  • "**.c" matches both "foo.c" and "mydir/foo.c"
  • "*/*.c" matches "bar/foo.c" but not "baz/bar/foo.c"
  • "??*/*" matches "ab/foo" and "abc/foo" but not "a/foo" or "a/b/foo"
This modified behaviour is equivalent to the pattern matching style used by the shells of some of UnZip's supported target OSs (one example is Acorn RISC OS). This option may not be available on systems where the Zip archive's internal directory separator character '/' is allowed as regular character in native operating system filenames. (Currently, unzip uses the same pattern matching rules for both wildcard zipfile specifications and zip entry selection patterns in most ports. For systems allowing `/' as regular filename character, the -W option would not work as expected on a wildcard zipfile specification.)
-X [VMS, Unix, OS/2, NT, Tandem] restore owner/protection info (UICs and ACL entries) under VMS, or user and group info (UID/GID) under Unix, or access control lists (ACLs) under certain network-enabled versions of OS/2 (Warp Server with IBM LAN Server/Requester 3.0 to 5.0; Warp Connect with IBM Peer 1.0), or security ACLs under Windows NT. In most cases this will require special system privileges, and doubling the option (-XX) under NT instructs unzip to use privileges for extraction; but under Unix, for example, a user who belongs to several groups can restore files owned by any of those groups, as long as the user IDs match his or her own. Note that ordinary file attributes are always restored--this option applies only to optional, extra ownership info available on some operating systems. [NT's access control lists do not appear to be especially compatible with OS/2's, so no attempt is made at cross-platform portability of access privileges.]
-Y [VMS] treat archived file name endings of ".nnn" (where "nnn" is a decimal number) as if they were VMS version numbers (";nnn"). (The default is to treat them as file types.) Example: "a.b.3" -> "a.b;3".
-$ [MS-DOS, OS/2, NT] restore the volume label if the extraction medium is removable (e.g., a diskette). Doubling the option (-$$) allows fixed media (hard disks) to be labelled as well. By default, volume labels are ignored.
-/ extensions [Acorn only] overrides the extension list supplied by the Unzip$Ext environment variable. During extraction, filename extensions that match one of the items in this extension list are swapped in front of the base name of the extracted file.
-: [all but Acorn, VM/CMS, MVS, Tandem] allows to extract archive members into locations outside of the current "extraction root folder". For security reasons, unzip normally removes "parent dir" path components ("../") from the names of extracted file. This safety feature (new for version 5.50) prevents unzip from accidentally writing files to "sensitive" areas outside the active extraction folder tree head. The -: option lets unzip switch back to its previous, more liberal behaviour, to allow exact extraction of (older) archives that used "../" components to create multiple directory trees at the level of the current extraction folder. This option does not enable writing explicitly to the root directory ("/"). To achieve this, it is necessary to set the extraction target folder to root (e.g., -d / ). However, when the -: option is specified, it is still possible to implicitly write to the root directory by specifying enough "../" path components within the zip archive. Use this option with extreme caution.
-^ [Unix only] allow control characters in names of extracted zip archive entries. On Unix, a file name may contain any (8-bit) character code with the two exception '/' (directory delimiter) and NUL (0x00, the C string termination indicator), unless the specific file system has more restrictive conventions. Generally, this allows to embed ASCII control characters (or even sophisticated control sequences) in file names, at least on 'native' Unix file systems. However, it may be highly suspicious to make use of this Unix "feature". Embedded control characters in file names might have nasty side effects when displayed on the screen by some listing code without sufficient filtering. And, for ordinary users, it may be difficult to handle such file names (e.g., when trying to specify it for open, copy, move, or delete operations). Therefore, unzip applies a filter by default that removes potentially dangerous control characters from the extracted file names. The -^ option allows to override this filter in the rare case that embedded filename control characters are to be intentionally restored.
-2 [VMS] force unconditionally conversion of file names to ODS2-compatible names. The default is to exploit the destination file system, preserving case and extended file name characters on an ODS5 destination file system; and applying the ODS2-compatibility file name filtering on an ODS2 destination file system.
Options

unzip's default behavior may be modified via options placed in an environment variable. This can be done with any option, but it is probably most useful with the -a-L-C-q-o, or -n modifiers: make unzip auto-convert text files by default, make it convert filenames from uppercase systems to lowercase, make it match names case-insensitively, make it quieter, or make it always overwrite or never overwrite files as it extracts them. For example, to make unzip act as quietly as possible, only reporting errors, one would use one of the following commands:

Unix Bourne shell:

UNZIP=-qq; export UNZIP

Unix C shell:

setenv UNZIP -qq

OS/2 or MS-DOS:

set UNZIP=-qq

VMS (quotes for lowercase):

define UNZIP_OPTS "-qq"

Environment options are, in effect, considered to be just like any other command-line options, except that they are effectively the first options on the command line. To override an environment option, one may use the "minus operator" to remove it. For instance, to override one of the quiet-flags in the example above, use the command below.

unzip --q[other options] zipfile

The first hyphen is the normal switch character, and the second is a minus sign, acting on the q option. Thus the effect here is to cancel one quantum of quietness. To cancel both quiet flags, two (or more) minuses may be used:

unzip -t--q zipfile
unzip ---qt zipfile

(the two are equivalent). This may seem awkward or confusing, but it is reasonably intuitive: just ignore the first hyphen and go from there. It is also consistent with the behavior of Unix nice.

As suggested by the examples above, the default variable names are UNZIP_OPTS for VMS (where the symbol used to install unzip as a foreign command would otherwise be confused with the environment variable), and UNZIP for all other operating systems. For compatibility with zipUNZIPOPT is also accepted. If both UNZIP and UNZIPOPT are defined, however, UNZIP takes precedence. unzip's diagnostic option (-v with no zipfile name) can be used to check the values of all four possible unzip and zipinfo environment variables.

The timezone variable (TZ) should be set according to the local timezone for the -f and -u to operate correctly. See the description of -f above for details. This variable may also be necessary to get timestamps of extracted files to be set correctly. The WIN32 (Win9x/ME/NT4/2K/XP/2K3) port of unzip gets the timezone configuration from the Registry, assuming it is correctly set in the Control Panel. The TZ variable is ignored for this port.

Decryption

Encrypted archives are fully supported by Info-ZIP software, but due to United States export restrictions, de-/encryption support might be disabled in your particular compiled binary. However, since the spring of 2000, US export restrictions have been liberated, and our source archives do now include full crypt code. In case you need binary distributions with crypt support enabled, see the file "WHERE" in any Info-ZIP source or binary distribution for locations both inside and outside the US.

Some compiled versions of unzip may not support decryption. To check a version for crypt support, either attempt to test or extract an encrypted archive, or else check unzip's diagnostic screen (see the -v option above) for "[decryption]" as one of the special compilation options.

As noted above, the -P option may be used to supply a password on the command line, but at a cost in security. The preferred decryption method is to extract normally; if a zipfile member is encrypted, unzip will prompt for the password without echoing what is typed. unzip continues to use the same password as long as it appears to be valid, by testing a 12-byte header on each file. The correct password will always check out against the header, but there is a 1-in-256 chance that an incorrect password will as well. (This is a security feature of the PKWARE zipfile format; it helps prevent brute-force attacks that might otherwise gain a large speed advantage by testing only the header.) In the case that an incorrect password is given but it passes the header test anyway, either an incorrect CRC will be generated for the extracted data or else unzip will fail during the extraction because the "decrypted" bytes do not constitute a valid compressed data stream.

If the first password fails the header check on some file, unzip will prompt for another password, and so on until all files are extracted. If a password is not known, entering a null password (that is, just a carriage return or "Enter") is taken as a signal to skip all further prompting. Only unencrypted files in the archive(s) will thereafter be extracted. (In fact, that's not quite true; older versions of zip and zipcloak allowed null passwords, so unzip checks each encrypted file to see if the null password works. This may result in "false positives" and extraction errors, as noted above.)

Archives encrypted with 8-bit passwords (for example, passwords with accented European characters) may not be portable across systems and/or other archivers. This problem stems from the use of multiple encoding methods for such characters, including Latin-1 (ISO 8859-1) and OEM code page 850. DOS PKZIP 2.04g uses the OEM code page; Windows PKZIP 2.50 uses Latin-1 (and is therefore incompatible with DOS PKZIP); Info-ZIP uses the OEM code page on DOS, OS/2 and Win3.x ports but ISO coding (Latin-1 etc.) everywhere else; and Nico Mak's WinZip 6.x does not allow 8-bit passwords at all. unzip 5.3 (or newer) attempts to use the default character set first (e.g., Latin-1), followed by the alternate one (e.g., OEM code page) to test passwords. On EBCDIC systems, if both of these fail, EBCDIC encoding will be tested as a last resort. (EBCDIC is not tested on non-EBCDIC systems, because there are no known archivers that encrypt using EBCDIC encoding.) ISO character encodings other than Latin-1 are not supported. The new addition of (partially) Unicode (resp. UTF-8) support in UnZip 6.0 has not yet been adapted to the encryption password handling in unzip. On systems that use UTF-8 as native character encoding, unzip tries decryption with the native UTF-8 encoded password; the built-in attempts to check the password in translated encoding have not yet been adapted for UTF-8 support and will consequently fail.

查看英文版

查看中文版

unzip 示例

unzip hope.zip

hope.zip存档解压缩到当前目录中,根据需要创建子目录以匹配存档的文件层次结构。

unzip -j hope.zip

无论存档的内部目录结构如何,都仅将它们从文件hope.zip提取到当前目录中。

unzip -tq hope.zip

测试hope.zip是否存在错误,但不要提取任何内容。 q表示“安静”模式,该模式指示解压缩仅返回摘要消息,而不返回更详细的消息。

unzip -ca hope.zip *.txt

将归档文件hope.zip中包含的扩展名为.txt的所有文件的内容显示到标准输出。

unzip hope.zip "*.[ch]" Makefile -d /tmp

hope.zip中将所有扩展名为.c.h的C源文件以及任何名为Makefile的文件提取到目录/ tmp中。

unzip -C hope.zip "*.[ch]" Makefile -d /tmp

与上述命令相同,但不区分大小写; 它还会提取任何扩展名为.C.H的文件,任何名为MAKEFILE的文件,任何名为MakeFile的文件,等等。

unzip -fo hope.zip

从存档的hope.zip中提取文件,但前提是它们是比已经存在的文件新的版本。

unzip -l hope.zip

在不提取任何内容的情况下显示hope.zip内容的清单。

unzip hope.zip

Unzip the hope.zip archive into the current directory, creating subdirectories as needed to match the archive's file hierarchy.

unzip -j hope.zip

Extract the files from archive hope.zip into the current directory only, regardless of the archive's internal directory structure.

unzip -tq hope.zip

Test hope.zip for errors, but do not extract anything. The q indicates "quiet" mode, which instructs unzip to return only a summary message, rather than a more detailed one.

unzip -ca hope.zip *.txt

Display the contents of all files with the extension .txt contained in the archive hope.zip to the standard output.

unzip hope.zip "*.[ch]" Makefile -d /tmp

Extract from the hope.zip archive any C source files with the extensions .c and .h, and any files named Makefile, into the directory /tmp.

unzip -C hope.zip "*.[ch]" Makefile -d /tmp

Same as the above command, but case-insensitive; it will also extract any files with the extensions .C or .H, any files named MAKEFILE, any files named MakeFile, etc.

unzip -fo hope.zip

Extract files from the archive hope.zip, but only if they are newer versions than the files that already exist.

unzip -l hope.zip

Display a listing of the contents of hope.zip without extracting anything.

查看英文版

查看中文版

其他命令行

userdel | usermod | ul | umask | unalias | uname | uncompress | unhash | uniq | until | unlink | unpack | uptime | useradd |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条