使用 zip 扩展解压 gz 档案

per*_*ika 7 zip gzip

我有许多 gzip 档案;但是他们有一个不是 gz 的 zip 扩展名:***.zip

当我尝试用 解压缩它们时unzip,我得到not a zip archive错误,而用 gunzip 我得到unknown suffix: zip

这里到底发生了什么?

use*_*274 11

默认情况下,gzip将仅解压缩具有有限列表中扩展名的文件,而不是检查文件magic以确定它是否是 gzip 文件。来自gzip.c:: 中的评论get_suffix()

/* ========================================================================                 
 * Return a pointer to the 'z' suffix of a file name, or NULL. For all                      
 * systems, ".gz", ".z", ".Z", ".taz", ".tgz", "-gz", "-z" and "_z" are                     
 * accepted suffixes, in addition to the value of the --suffix option.                      
Run Code Online (Sandbox Code Playgroud)

要使用实际上经过 gzip 压缩但未命名为以下gzip预期约定的输入文件,请按照gzip手册页明确提供后缀:

-S .suf --suffix .suf

... 解压缩时,将 .suf 添加到要尝试的后缀列表的开头,当从输入文件名派生输出文件名时。

$ gunzip -S .zip foo.zip
Run Code Online (Sandbox Code Playgroud)

或使用重定向来防止gzip看到文件名:

$ gunzip < foo.zip > foo.txt
Run Code Online (Sandbox Code Playgroud)