The unzip(1) will list, test, or extract files from a ZIP
archive, commonly found on MS-DOS systems. The default behavior
(with no options) is to extract into the current directory (and
subdirectories below it) all files from the specified ZIP archive.
A companion program, zip(1), creates ZIP archives; both
programs are compatible with PKWARE's PKZIP and PKUNZIP for
MS-DOS.
The main operands are the archive file, the members, a
list of members to be excluded from processing, and a directory in
which the extraction should take place. Only the archive is
required.
file[.zip]
The path of one or more ZIP archives. 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 file
name can be a wildcard; the path itself cannot. Wildcard
expressions are similar to egrep(1) (regular) expressions
and can contain:
*
Matches a sequence of 0 or more characters.
?
Matches exactly one 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, the range of characters within the brackets is
complemented (that is, anything except the characters inside
the brackets is considered a match).
(Be sure to quote any character that might otherwise be
interpreted or modified by the operating system or shells.) If no
matches are found, the specification is assumed to be a literal
file name; if that also fails, the suffix .zip is appended.
Note that self-extracting ZIP files are supported; just specify the
.exe suffix (if any) explicitly.
file
The file, if specified, is the archive members to be
processed. You can match multiple members with regular expressions
(wildcards) as above. Again, be sure to quote expressions that
would otherwise be expanded
-dexdir
Extract files in the 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 immediately after the zipfile specification, or
between the file and the -x option.
-xxfile
Exclude the archive members xfile from processing.
Because wildcard characters match directory separators ('/'), this
option can be used to exclude any files that are in subdirectories.
For example, "unzip cat *.[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.
Besides those operands, unzip(1) also accepts the
following options, which specify actions:
-c
Extract files to stdout/screen ("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.
-f
Freshen existing files; that is, extract only those files that
already exist on disk and which are newer than the disk copies. By
default unzip(1) queries before overwriting, but the
-o option can be used to suppress the queries.
-l
List archive files (short format). The name, uncompressed file
size, and modification date and time of each specified file is
printed, along with totals for all files specified. If a file was
archived from a single-case file system (for example, the MS-DOS
file allocation table (FAT) file system) and the -U option
was not given, the file name is converted to lowercase and is
prefixed with a caret (^). In addition, the archive comment and
individual file comments (if any) are displayed.
-p
Extract files to pipe (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 cyclic redundancy check (CRC), an enhanced
checksum, of the expanded file with the original file's stored CRC
value.
-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; in addition, it extracts those files that do not
already exist on disk.
-v
List archive files (verbose format). In addition to the
information given by the -l option, the compression method,
compressed size, compression ratio and 32-bit CRC is listed.
-z
Display only the archive comment.
-Z
zipinfo(1) mode. If the first option on the command line
is -Z, the remaining options are taken to be
zipinfo(1) options. See the appropriate manual page for a
description of these options.
The following options modify the behavior of one or more
actions:
-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(1) as text files (those with the 't'
rather than 'b'label in zipinfo(1) listings ) to be
automatically extracted as such, converting line endings,
end-of-file characters, and the character set itself as necessary.
For example, Interix files use line feeds (LFs) for end-of-line
(EOL) and have no end-of-file (EOF) marker; Macintosh computers use
carriage returns (CRs) for EOLs; and most PC-based operating
systems use CR+LF for EOLs and CTRL+Z for EOF. In addition, IBM
mainframes and the Michigan Terminal System use EBCDIC rather than
the more common ASCII character set, and Windows supports Unicode.)
Note that the zip(1) utility's identification of text files
is by no means perfect; some "text" files can actually be binary
and vice versa. The unzip(1) utility 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.
-j
Junk paths. The archive's directory structure is not recreated;
all files are deposited in the extraction directory (by default,
the current one).
-n
Never overwrite existing files. If a file already exists, skip
the extraction of that file without prompting. By default,
unzip(1) queries before extracting any file that already
exists; the user can 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.
-o
Overwrite existing files without prompting. This is a dangerous
option, so use it with care. (It is often used with -f,
however.)
-q
Perform operations quietly (-qq=even quieter).
Ordinarily, unzip(1) prints the names of the files it is
extracting or testing, the extraction methods, any file or zipfile
comments that might be stored in the archive, and possibly a
summary when finished with each archive. The -q and
-qq options suppress the printing of some or all of these
messages.
-s
[OS/2, Windows, MS-DOS] Convert spaces in file names to
underscores. By default, unzip(1) extracts file names with
spaces intact (for example, "EA DATA. SF"). This can be awkward,
however, because MS-DOS in particular does not gracefully support
spaces in file names. Conversion of spaces to underscores can
eliminate this awkwardness in some cases.
-U
Leave file names uppercase if created under MS-DOS, VMS, and so
on. Depending on the archiver, files archived under single-case
file systems can be stored as all-uppercase names; this can be
awkward when extracting to a case-preserving file system such as
OS/2 HPFS or a case-sensitive one, such as under Interix. By
default unzip(1) converts such file names to lowercase; this
option causes all file names to be extracted exactly as they are
stored (except in the cases of truncation, conversion of
unsupported characters, and the like).
-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 file names
to particularly short lengths, the version numbers can be truncated
or stripped regardless of this option.)
-X
[VMS] Restore owner/protection info (might require system
privileges). Ordinary file attributes are always restored, but this
option also allows unique identifier codes(UICs) to be
restored.
-$
[MS-DOS, OS/2, Windows, Amiga] Restore the volume label if the
extraction medium is removable (as, for example, in the case of a a
diskette). Doubling the option (-$$) allows fixed media
(hard disks) to be labelled as well. By default, volume labels are
ignored.
The unzip(1)utility's default behavior can be modified by
using options placed in an environment variable. This can be done
with any option, but it is probably most useful with the -q,
-a, -o, or -n modifiers: make unzip(1)
quieter by default, make it auto-convert text files, or make it
always overwrite or never overwrite files as it extracts them. For
example, to make unzip(1) act as quietly as possible, only
reporting errors, one would use one of the following commands:
Environment options are 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, use
the "minus operator" to remove it. For instance, to override one of
the quiet flags in the example above, use the command
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 can be used:
unzip -t--q zipfile
unzip ---qt zipfile
(the two are equivalent). This might seem awkward or confusing,
but it is reasonably intuitive: just ignore the first hyphen and go
from there.
To use unzip(1) to extract all members of the archive
letters.zip into the current directory and subdirectories
below it, creating any subdirectories as necessary, use:
unzip letters"
To extract all members of letters.zip into the current
directory only, use:
unzip -j letters
To test letters.zip, printing only a summary message
indicating whether the archive is OK or not, use:
unzip -tq letters
To extract to standard output all members of letters.zip
whose names end in .tex, auto-converting to the local
end-of-line convention and piping the output into more(1),
use:
unzip -ca letters \*.tex | more"
(The backslash before the asterisk is required when the shell
expands wildcards, as with Interix; double quotes could have been
used instead, as in the source example provided later in this
topic.) To extract the binary file paper1.dvi to standard
output and pipe it to a printing program, use:
unzip -p articles paper1.dvi | dvips
To extract all FORTRAN and C source files--*.f, *.c, *.h, and
Makefile--into the /tmp directory,use:
unzip source.zip "*.[fch]"" Makefile -d /tmp"
(the double quotes are necessary to have the shell treat the
enclosed characters as literals). To extract only newer versions of
the files already in the current directory, without querying, use
the following (NOTE: Be careful when unzipping in one time zone a
zip file created in another. ZIP archives to date contain no
time-zone information, and a "newer" file from an eastern time zone
can, in fact, be older):
unzip -fo sources
To extract newer versions of the files already in the current
directory, and to create any files not already there (same caveat
as previous example), use:
unzip -uo sources"
In the last five examples, assume that UNZIP or UNZIP_OPTS is
set to -q. To do a singly quiet listing:
The current maintainer, being a lazy sort, finds it very useful
to define a pair of aliases: tt for "unzip -tq" and
ii for "unzip -Z" (or "zipinfo"). One can then simply type
"tt zipfile" to test an archive something that is worth making a
habit of doing. With luck unzip(1) will report "No errors
detected in zipfile.zip,".
Under DEC Ultrix, unzip(1) will sometimes fail on long
zipfiles (bad Cyclical Redundancy Checking (CRC), not always
reproducible). This is apparently due either to a hardware bug
(cache memory) or an operating system bug (improper handling of
page faults?).
Dates and times of stored directories are not restored.