Unzip gz archives with zip extension

5,632

By default, gzip will only decompress files with extensions from a limited list—rather than examining the file magic to determine if it is a gzip'd file. From a comment in 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.                      

To use input files which are in fact gzip'd but are not named following gzip's expected conventions, provide the suffix explicitly as per the gzip manual page:

-S .suf --suffix .suf

... When decompressing, add .suf to the beginning of the list of suffixes to try, when deriving an output file name from an input file name.

$ gunzip -S .zip foo.zip

or use redirection to prevent gzip from seeing the filename:

$ gunzip < foo.zip > foo.txt
Share:
5,632

Related videos on Youtube

perestroika
Author by

perestroika

Updated on September 18, 2022

Comments

  • perestroika
    perestroika over 1 year

    I have a number of gzip archives; however they have a zip extension not gz: ***.zip

    When I try to unzip them with unzip, I get not a zip archive error, and with gunzip I get unknown suffix: zip

    What is going on here really?

    • Ben Sandeen
      Ben Sandeen over 6 years
      Is there any reason that you can't rename the files to have a .gz extension?
  • ivanivan
    ivanivan over 6 years
    +1 for a cause - but why not cat file.zip | gunzip > file.ext for the quick lazy way of doing it? And if cat will interrupt due to the "special" characters that would show in a binary, would dd work in its place - dd if=filezame.zip | gunzip > filename.ext