unzip lists, tests, or extracts 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, creates ZIP archives; both programs are compatible with archives created by PKWARE's PKZIP and PKUNZIP for MS-DOS, but in many cases the program options or default behaviors differ.
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 file name can be a wildcard; the path itself cannot. Wildcard expressions are similar to egrep (regular) expressions 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).
(Be sure to quote any character that might otherwise be interpreted or modified by the operating system, particularly on UNIX and VMS systems.) If no matches are found, the specification is assumed to be a literal file name; 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.
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
-vin Options below.) Regular expressions (wildcards) may be used to match multiple members; see above. Again, be sure to quote expressions that would otherwise be expanded or modified by the operating system.
An optional list of archive members to be excluded from processing. Since wildcard characters match directory separators (`/'), 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
-xoption, all C source files in all directories within the zipfile would be extracted.
An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the
-doption 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 -xoption. 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 the C-Shell (csh) into the name of the user's home directory, but -d~ is treated as a literal subdirectory ~ of the current directory.
Note that, in order to support obsolescent hardware, unzip's usage screen is limited to 22 or 23 lines and should therefore be considered only a reminder of the basic unzip syntax rather than an exhaustive list of all possible flags.
extracts files to stdout/screen ("CRT"). This option is similar to the
-poption except that the name of each file is printed as it is extracted, the -aoption is allowed, and ASCII-EBCDIC conversion is automatically performed if appropriate. This option is not listed in the unzip usage screen. -f
freshens existing files, that is, 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
-ooption may be used to suppress the queries. Note that under many operating systems, the TZ (timezone) environment variable must be set correctly in order for -fand -uto 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) and the necessity to compare the two. A typical TZ value is PST8PDT (US Pacific time with automatic adjustment for Daylight Savings Time or "summer time"). -l
lists 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
-loption also lists columns for the sizes of stored OS/2 extended attributes (EAs) and OS/2 access control lists (ACLs). In addition, 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 -Loption was given, the file name is converted to lowercase and is prefixed with a caret (^). -p
extracts 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).
tests 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.
[most operating systems] sets the timestamp on the archives to of the newest file in each one. This corresponds to zip's
-gooption except that it can be used on wildcard zipfiles (for example, "unzip -T \*.zip") and is much faster. -u
updates existing files and create new ones if needed. This option performs the same function as the
-foption, 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 -fabove for information on setting the timezone properly. -v
enters verbose mode or prints 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,
-vlists archive files verbosely, adding to the basic -linfo the compression method, compressed size, compression ratio and 32-bit CRC. When no zipfile is specified (that is, the complete command is simply 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 (for example, -t) to produce more verbose or debugging output; this is not yet fully implemented but may be in future releases. -z
displays only the archive comment.
converts text files. Ordinarily all files are extracted exactly as they are stored (as "binary" files). The
-aoption 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. In addition, 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 -aoption. The -aaoption forces all files to be extracted as text, regardless of the supposed file type. -b
treats all files as binary (no text conversions). This is a shortcut for
matches file names case-insensitively. unzip's philosophy is "you get what you ask for" (this is also responsible for the
-L/ -Uchange; 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 file names case-sensitively. That is, specifying makefile on the command line only matches 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 -Coption may be used to force all file name matches to be case-insensitive. In the example above, all three files would then match makefile (or make*, or similar). The -Coption affects files in both the normal file list and the excluded-file list (xlist). -j
junks paths. The archive's directory structure is not recreated; all files are deposited in the extraction directory (by default, the current one).
converts to lowercase any file name 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
-Uoption, which is now obsolete and may 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 on a UNIX system. By default unzip lists and extracts such file names 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. -M
pipes all output through an internal pager similar to the 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 space bar. unzip can be terminated by pressing the q key and, on some systems, the Enter/Return key. Unlike 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 scrolls 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.
never overwrites 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.
overwrites existing files without prompting. This is a dangerous option, so use it with care. (It is often used with
-f, however.) -Ppassword
uses password to decrypt 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 plain text 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.)
performs operations quietly (
-q[ q] option suppresses the printing of some or all of these messages. -s
[OS/2, NT, MS-DOS] converts spaces in file names to underscores. Since all PC operating systems allow spaces in file names, unzip by default extracts file names with spaces intact (for example, "EA DATA. SF"). This can be awkward, however, since MS-DOS in particular does not gracefully support spaces in file names. Conversion of spaces to underscores can eliminate the awkwardness in some cases.
(obsolete; to be removed in a future release) leaves file names uppercase if created under MS-DOS, VMS, etc. See
retains (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 may be truncated or stripped regardless of this option.)
[VMS, UNIX, OS/2] restores owner/protection info (UICs) under VMS, or user and group info (UID/GID) on UNIX systems; 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). In most cases this requires special system privileges; but on UNIX systems, 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. [Note that NT's access control lists are probably compatible with OS/2's. A future release may support cross-platform storage and restoration of ACLs.]
[MS-DOS, OS/2, NT] restores the volume label if the extraction medium is removable (for example, a diskette). Doubling the option (
-$$) allows fixed media (hard disks) to be labelled as well. By default, volume labels are ignored.
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
UNZIP=-qq; export UNZIP KornShell setenv UNZIP -qq C-Shell (csh) set UNZIP=-qq command.exe or cmd.exe define UNZIP_OPTS "-qq" VMS (quotes for lowercase)
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
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 nice on UNIX systems.
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 zip.
UNZIPOPT is also accepted (don't ask). If both UNZIP and
UNZIPOPT are defined, however, UNZIP takes precedence.
unzip's diagnostic option (
The timezone variable (TZ) should be set according to the
local timezone in order for the
Encrypted archives are fully supported.
As noted above, the
If the first password fails the header check on some file, unzip prompts 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) is taken as a signal to skip all further prompting. Only unencrypted files in the archive(s) are extracted thereafter. (Actually 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 Latin-1 everywhere else; and Nico Mak's WinZip 6.x does not allow 8-bit passwords at all. unzip 5.3 attempts to use the default character set first (for example, Latin-1), followed by the alternate one (for example, OEM code page) to test passwords. On EBCDIC systems, if both of these fail, EBCDIC encoding will be tested as a last resort. (Since there are no known archivers that encrypt using EBCDIC encoding, EBCDIC is not tested on non-EBCDIC systems.) ISO character encodings other than Latin-1 are not supported.
To use unzip to extract all members of the archive letters.zip into the current directory and subdirectories below it, creating any subdirectories as necessary:
To extract all members of letters.zip into the current directory only:
unzip -j letters
To test letters.zip, printing only a summary message indicating whether the archive is OK or not:
unzip -tq letters
To test all zipfiles in the current directory, printing only the summaries:
unzip -tq \*.zip
(The backslash before the asterisk is only required if the shell expands wildcards, as on UNIX systems; double quotes could have been used instead, as in the source examples below.) 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:
unzip -ca letters \*.tex | more
To extract the binary file paper1.dvi to standard output and pipe it to a printing program:
unzip -p articles paper1.dvi | dvips
To extract all FORTRAN and C source files--*.f, *.c, *.h, and Makefile--into the /tmp directory:
unzip source.zip "*.[fch]" Makefile -d /tmp
(the double quotes are necessary only on UNIX systems and only if globbing is turned on). To extract all FORTRAN and C source files, regardless of case (for example, both *.c and *.C, and any makefile, Makefile, MAKEFILE, or similar):
unzip -C source.zip "*.[fch]" makefile -d /tmp
To extract any such files but convert any uppercase MS-DOS or VMS names to lowercase and convert the line-endings of all of the files to the local standard (without respect to any files that might be marked "binary"):
unzip -aaCL source.zip "*.[fch]" makefile -d /tmp
To extract only newer versions of the files already in the current directory, without querying (NOTE: be careful of unzipping in one timezone a zipfile created in another--ZIP archives to date contain no timezone information, and a "newer" file from an eastern timezone may, 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):
unzip -uo sources
To display a diagnostic screen showing which unzip and zipinfo options are stored in environment variables, whether decryption support was compiled in, the compiler with which unzip was compiled, etc.:
In the last five examples, assume that UNZIP
is set to
unzip -l file.zip
To do a doubly quiet listing:
unzip -ql file.zip
(Note that the .zip is generally not necessary.) To do a standard listing:
unzip --ql file.zip
unzip -l-q file.zip
unzip -l--q file.zip (extra minuses don't hurt)
Contains the format to be used by cpio, tar, pax, vpax, zip, or unzip when reading and writing file names to an archive. The value must be one of ASCII_ANSI, ASCII_OEM, or UTF-8 (or their equivalents) as described in the File Character Formats section of the unicode reference page.
When this variable is unset or it is set to a value other than those listed earlier, the default OEM character set is used.
The exit status (or error level) approximates the exit codes defined by PKWARE and takes on the following values, except under VMS:
normal; no errors or warnings detected.
one or more warning errors were encountered, but processing completed successfully anyway. This includes zipfiles where one or more files was skipped due to unsupported compression method or encryption with an unknown password.
a generic error in the zipfile format was detected. Processing may have completed successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.
a severe error in the zipfile format was detected. Processing probably failed immediately.
unzip was unable to allocate memory for one or more buffers during program initialization.
unzip was unable to allocate memory or unable to obtain a tty to read the decryption password(s).
unzip was unable to allocate memory during decompression to disk.
unzip was unable to allocate memory during in-memory decompression.
the specified zipfiles were not found.
invalid options were specified on the command
no matching files were found.
the disk is (or was) full during extraction.
the end of the ZIP archive was encountered prematurely.
the user aborted unzip prematurely with CTRL-C (or similar).
testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.
no files were found due to bad decryption password(s). (If even one file is successfully processed, however, the exit status is 1.)
VMS interprets standard return values from UNIX (or PC) systems as other, scarier-looking things, so unzip instead maps them into VMS-style status codes. The current mapping is as follows: 1 (success) for normal exit, 0x7fff0001 for warning errors, and (0x7fff000? + 16*normal_unzip_exit_status) for all other errors, where the ? is 2 (error) for unzip values 2 and 9-11, and 4 (fatal error) for the remaining ones (3-8, 50, 51). In addition, there is a compilation option to expand upon this behavior: defining RETURN_CODES results in a human-readable explanation of what the error status means.
The current maintainer, being a lazy sort, finds it very
useful to define a pair of aliases: tt for "unzip
to test an archive, something that is worth making a habit of doing. With luck unzip reports "No errors detected in compressed data of zipfile.zip", after which one may breathe a sigh of relief.
The maintainer also finds it useful to set the UNZIP
environment variable to
Multi-part archives are not yet supported, except in conjunction with zip.
(All parts must be concatenated together
in order, and then zip
Archives read from standard input are not yet supported, except with funzip (and then only the first member of the archive can be extracted).
Dates, times, and permissions of stored directories are not restored except under UNIX.
The primary Info-ZIP authors (current zip-bugs workgroup) are: Greg "Cave Newt" Roelofs (UnZip); Onno van der Linden (Zip); Jean-loup Gailly (compression); Mark Adler (decompression, fUnZip); Christian Spieler (VMS, MS-DOS, shared code, general Zip and UnZip integration); Mike White (Windows GUI, Windows DLLs); Kai Uwe Rommel (OS/2); Paul Kienitz (Amiga, Windows 95); Karl Davis and Sergio Monesi (Acorn RISC OS); George Petrov (MVS, VM/CMS); Harald Denker (Atari, MVS); John Bush (Amiga); Hunter Goatley (VMS); Antoine Verheijen (Macintosh); Chris Herborth (Atari, QNX, BeBox); Johnny Lee (MS-DOS, NT, Windows 95); Steve Salisbury (NT, Windows 95); and Robert Heath (Windows GUI). The author of the original unzip code upon which Info-ZIP's was based is Samuel H. Smith; Carl Mascott did the first UNIX port; and David P. Kirschbaum organized and led Info-ZIP in its early days. The full list of contributors to UnZip has grown quite large; please refer to the CONTRIBS file in the unzip source distribution for a relatively complete version.
v1.2 15 Mar 89 Samuel H. Smith v2.0 9 Sep 89 Samuel H. Smith v2.x fall 1989 many Usenet contributors v3.0 1 May 90 Info-ZIP (DPK, consolidator) v3.1 15 Aug 90 Info-ZIP (DPK, consolidator) v4.0 1 Dec 90 Info-ZIP (GRR, maintainer) v4.1 12 May 91 Info-ZIP v4.2 20 Mar 92 Info-ZIP (zip-bugs subgroup, GRR) v5.0 21 Aug 92 Info-ZIP (zip-bugs subgroup, GRR) v5.01 15 Jan 93 Info-ZIP (zip-bugs subgroup, GRR) v5.1 7 Feb 94 Info-ZIP (zip-bugs subgroup, GRR) v5.11 2 Aug 94 Info-ZIP (zip-bugs subgroup, GRR) v5.12 28 Aug 94 Info-ZIP (zip-bugs subgroup, GRR) v5.2 30 Apr 96 Info-ZIP (zip-bugs subgroup, GRR) v5.3 22 Apr 97 Info-ZIP (Zip-Bugs subgroup, GRR) v5.31 31 May 97 Info-ZIP (Zip-Bugs subgroup, GRR) v5.32 3 Nov 97 Info-ZIP (Zip-Bugs subgroup, GRR) v5.4 28 Nov 98 Info-ZIP (Zip-Bugs subgroup, SPC) v5.41 16 Apr 00 Info-ZIP (Zip-Bugs subgroup, SPC)
All UNIX systems. Windows 2000. Windows XP. Windows Server 2003. Windows Vista. Windows 7. Windows Server 2008. Windows 8. Windows Server 2012.
unzip is also available other systems including MSDOS, OS/2, Minix, Atari, Macintosh, Amiga, and Acorn RISC OS.
MKS Toolkit for Power Users
MKS Toolkit for System Administrators
MKS Toolkit for Developers
MKS Toolkit for Interoperability
MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition
- bzdiff, bzgrep, bzip2, bzmore, cpio, gzip, mkszip, pax, tar, uncompress, unpack, zcat, zip, zipinfo
MKS Toolkit Backup and Tape Handling Solutions Guide
MKS Toolkit 9.5 Documentation Build 3.