Hi.
The gunzip command, like most of the *nix commands, does one thing well. In the case of gzip / gunzip, that is compressing / uncompressing files. It does not gather files together like many Windows utilities, zip, winzip, pkzip, etc. In the *nix world, the gathering is done with a separate utility, the most common being tar.
So the usual method of working in *nix is run tar to get a single file of a collection of files, and then, as a separate step, compress that file. The result is often a name that looks like name.tar.gz.
The gunzip command, as a convenience, will uncompress a zip file, but only if it has a single element. The way that gunzip works is to uncompress the file to a temporary file, and (effectively) copy that file back onto the name.zip file, so the original file is essentially replaced. Other utilities allow the name.zip file to remain, and create additional files that were in the archive. Both the commands unzip and 7z work like that.
So if one has a zip archive with more than one element, one needs to:
a) use a command different from gunzip, or
b) re-create the zip archive with single elements.
I quickly wrote a script that illustrates many of the topics we have discussed:
#!/usr/bin/env bash
# @(#) s0 Demonstrate file extension issues with unzip, gunzip, 7z.
# 7zip: http://p7zip.sourceforge.net/
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
# export PATH="/usr/local/bin:/usr/bin:/bin"
version >/dev/null 2>&1 && version "=o" unzip 7z && gunzip -V | head -1
rm -f t1 t1.zip t1.sas7bdat t2 t2.zip t2.sas7bdat
FILE=${1-data1}
pl " Data file $FILE:"
head -20 $FILE
pl " Create zip files with more than one element:"
rm -f t1.zip t1.sas7bdat t2.sas7bdat
cp $FILE t1.sas7bdat
cp $FILE t2.sas7bdat
zip t1.zip t1.sas7bdat t2.sas7bdat
file t1.zip
ls -lgG t1.sas7bdat t2.sas7bdat t1.zip
pl " unzip with gunzip, expect failure, more than one element in archive":
rm -f t1.sas7bdat t2.sas7bdat
gunzip -S .zip t1.zip
ls -lgG t*
pl " unzip with 7z, expect success with multiple elements:"
rm -f t1.zip t1.sas7bdat t2.sas7bdat
cp $FILE t1.sas7bdat
cp $FILE t2.sas7bdat
zip t1.zip t1.sas7bdat t2.sas7bdat
file t1.zip
rm -f t1.sas7bdat t2.sas7bdat
ls -lgG t*
7z x t1.zip
ls -lgG t*
pl " Re-create zip file with only one element:"
rm -f t1.zip t1.sas7bdat t2.sas7bdat
cp $FILE t1.sas7bdat
zip t1.zip t1.sas7bdat
file t1.zip
ls -lgG t1.sas7bdat t1.zip
pl " unzip with unzip (keeps t1.zip):"
zip t1.zip t1.sas7bdat
rm t1.sas7bdat
unzip t1.zip
ls -lgG t1.sas7bdat t1.zip
pl " unzip with gunzip (removes t1.zip, loses extension):"
gunzip -S .zip t1.zip
ls -lgG t1*
pl " Unzip with 7z (keeps t1.zip):"
rm -f t1.zip t1.sas7bdat
cp $FILE t1.sas7bdat
zip t1.zip t1.sas7bdat
rm t1.sas7bdat
7z x t1.zip
ls -lgG t1.sas7bdat t1.zip
exit 0
producing:
% ./s0
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
UnZip 5.52 of 28 February 2005, by Debian. Original by Info-ZIP.
7z - ( /usr/bin/7z Jun 21 2008 )
gzip 1.3.12
-----
Data file data1:
Albuquerque, N.M.
Arlington, Texas
Atlanta, Ga.
Austin, Tex.
Baltimore, Md.
Boston, Mass.
Charlotte, N.C.
Chicago, Ill.
Cleveland, Ohio
Colorado Springs, Colo.
-----
Create zip files with more than one element:
adding: t1.sas7bdat (deflated 21%)
adding: t2.sas7bdat (deflated 21%)
t1.zip: Zip archive data, at least v2.0 to extract
-rw-r--r-- 1 160 Jun 7 08:23 t1.sas7bdat
-rw-r--r-- 1 538 Jun 7 08:23 t1.zip
-rw-r--r-- 1 160 Jun 7 08:23 t2.sas7bdat
-----
unzip with gunzip, expect failure, more than one element in archive:
gzip: t1.zip has more than one entry -- unchanged
-rw-r--r-- 1 538 Jun 7 08:23 t1.zip
-----
unzip with 7z, expect success with multiple elements:
adding: t1.sas7bdat (deflated 21%)
adding: t2.sas7bdat (deflated 21%)
t1.zip: Zip archive data, at least v2.0 to extract
-rw-r--r-- 1 538 Jun 7 08:23 t1.zip
7-Zip 4.58 beta Copyright (c) 1999-2008 Igor Pavlov 2008-05-05
p7zip Version 4.58 (locale=C,Utf16=off,HugeFiles=on,1 CPU)
Processing archive: t1.zip
Extracting t1.sas7bdat
Extracting t2.sas7bdat
Everything is Ok
Files: 2
Size: 320
Compressed: 538
-rw-r--r-- 1 160 Jun 7 2010 t1.sas7bdat
-rw-r--r-- 1 538 Jun 7 08:23 t1.zip
-rw-r--r-- 1 160 Jun 7 2010 t2.sas7bdat
-----
Re-create zip file with only one element:
adding: t1.sas7bdat (deflated 21%)
t1.zip: Zip archive data, at least v2.0 to extract
-rw-r--r-- 1 160 Jun 7 08:23 t1.sas7bdat
-rw-r--r-- 1 280 Jun 7 08:23 t1.zip
-----
unzip with unzip (keeps t1.zip):
updating: t1.sas7bdat (deflated 21%)
Archive: t1.zip
inflating: t1.sas7bdat
-rw-r--r-- 1 160 Jun 7 08:23 t1.sas7bdat
-rw-r--r-- 1 280 Jun 7 08:23 t1.zip
-----
unzip with gunzip (removes t1.zip, loses extension):
-rw-r--r-- 1 160 Jun 7 08:23 t1
-rw-r--r-- 1 160 Jun 7 08:23 t1.sas7bdat
-----
Unzip with 7z (keeps t1.zip):
adding: t1.sas7bdat (deflated 21%)
7-Zip 4.58 beta Copyright (c) 1999-2008 Igor Pavlov 2008-05-05
p7zip Version 4.58 (locale=C,Utf16=off,HugeFiles=on,1 CPU)
Processing archive: t1.zip
Extracting t1.sas7bdat
Everything is Ok
Size: 160
Compressed: 280
-rw-r--r-- 1 160 Jun 7 2010 t1.sas7bdat
-rw-r--r-- 1 280 Jun 7 08:23 t1.zip
Best wishes ... cheers, drl