unzip will list, test, or extract files from a ZIP archive. 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, but in many cases the program options or default behaviors differ.
Syntax
unzip [-Z] [-option ...] [-modifier ...] [-P password] zipfile [file ...] [-x xfile ...] [-d exdir] |
Path of the ZIP archive(s). If the file specification is a wildcard, each matching file is processed. Only the filename can be a wildcard; the path itself cannot. If no matches are found, the specification is assumed to be a literal filename; and if that also fails, the suffix .zip is appended. Note that self-extracting ZIP files are supported, as with any other ZIP archive.
An optional list of archive members to be processed, separated by spaces.
An optional list of archive members to be excluded from processing.
An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary 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 -x option. Options zipinfo mode. If the first option on the command line is -Z, the remaining options are taken to be zipinfo options. See the appropriate manual page for a description of these options.
freshen existing files, i.e., 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 -o option may be used to suppress the queries.
list 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.
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).
test 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.
set the timestamp of the archive(s) to that of the newest file in each one.
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, and in addition it extracts those files that do not already exist on disk.
list archive files (verbose format) or show diagnostic version info. This option has two purposes: when a zipfile is specified with no other options, -v lists archive files verbosely, adding to the basic -l info the compression method, compressed size, compression ratio and 32-bit CRC. When no zipfile is specified (that is, the complete command is simply "
display only the archive comment. Modifiers
convert text files. Ordinarily all files are extracted exactly as they are stored (as "binary" files). The -a option 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.
treat all files as binary (no text conversions).
save a backup copy of each overwritten file. The backup file is gets the name of the target file with a tilde and optionally a unique sequence number (up to 5 digits) appended. The sequence number is applied whenever another file with the original name plus tilde already exists. When used together with the "overwrite all" option -o, numbered backup files are never created. In this case, all backup files are named as the original file with an appended tilde, existing backup files are deleted without notice.
use case-insensitive matching for the selection of archive entries. Please note that the -C option does neither affect the search for the zipfile(s) nor the matching of archive entries to existing files on the extraction path. On a case-sensitive file system, unzip will never try to overwrite a file FOO when extracting an entry foo!
skip restoration of timestamps for extracted items. Normally, unzip tries to restore all meta-information for extracted items that are supplied in the Zip archive (and do not require privileges or impose a security risk). By specifying -D, unzip is told to suppress restoration of timestamps for directories explicitly created from Zip archive entries. The duplicated option -DD forces suppression of timestamp restoration for all extracted entries (files and directories). This option results in setting the timestamps for all extracted entries to the current time.
junk paths. The archive’s directory structure is not recreated; all files are deposited in the extraction directory (by default, the current one).
retain setuid/setgid/sticky file attributes. Without this flag, these attribute bits are cleared for security reasons.
convert to lowercase any filename originating on an uppercase-only operating system or file system. The -LL option forces conversion of every filename to lowercase, regardless of the originating file system.
pipe all terminal output through an internal pager similar to the more command.
never overwrite existing files. If a file already exists, skip the extraction of that file without prompting.
overwrite existing files without prompting.
use password to decrypt encrypted zipfile entries (if any).
perform operations quietly (-qq = even quieter). Ordinarily unzip prints the names of the files it’s extracting or testing, the extraction methods, any file or zipfile comments that may be stored in the archive, and possibly a summary when finished with each archive. The -q[q] options suppress the printing of some or all of these messages.
restore user and group info (UID/GID). In most cases this will require special system privileges.
allows to extract archive members into locations outside of the current "extraction root folder". For security reasons, unzip normally removes parent directory path components ("../") from the names of extracted file. This safety feature prevents unzip from accidentally writing files to sensitive areas outside the active extraction folder tree head. The -: option lets unzip switch to a more liberal behaviour, to allow exact extraction of archives that used "../" components to create multiple directory trees at the level of the current extraction folder. This option does not enable writing explicitly to the root directory ("/"). To achieve this, it is necessary to set the extraction target folder to root (e.g.
allow control characters in names of extracted ZIP archive entries. A file name may contain any (8-bit) character code with the two exception ’/’ (directory delimiter) and NUL (0x00). Generally, this allows to embed ASCII control characters in file names. By default, unzip applies a filter by default that removes potentially dangerous control characters from the extracted file names. The -^ option allows to override this filter. |
Variable
The following environment variables are read and used by unzip as described. UNZIP contains default options that will be used when running unzip. The contents of this environment variable will get added to the command line just after the unzip command. UNZIPOPT alternative default options variable (if UNZIP is empty or does not exist). |
Example
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:
To test letters.zip, printing only a summary message indicating whether the archive is OK or not:
To extract all C source files and Makefile, regardless of case, into the /tmp directory:
To extract newer versions of the files already in the current directory and create any files not already there:
|
Exit status
The exit status (or error level) approximates the exit codes defined by PKWARE and takes on the following values:
|
Restrictions
Multi-part archives are not yet supported, except in conjunction with zip. (All parts must be concatenated together in order, and then "fixed" using the -F or -FF options). Archives read from standard input are not yet supported, except with funzip (and then only the first member of the archive can be extracted). Archives encrypted with 8-bit passwords (e.g., passwords with accented European characters) may not be portable across systems and/or other archivers. Special files such as FIFO (named pipes), block devices and character devices are not restored even if they are somehow represented in the zipfile. Basically the only file types restored by unzip are regular files, directories and symbolic (soft) links. |
See also
funzip, zip, zipcloak, zipgrep, zipinfo, zipnote, zipsplit |