Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

unzip - list, test and extract compressed files in a ZIP archive

&pagelevel(4)&pagelevel

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]


zipfile

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.

file

An optional list of archive members to be processed, separated by spaces.

-x xfile

An optional list of archive members to be excluded from processing.

-d exdir

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

-Z

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.

-f

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.

-l

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.

-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 CRC (cyclic redundancy check, an enhanced checksum) of the expanded file with the original file’s stored CRC value.

-T

set the timestamp of the archive(s) to that of the newest file in each one.

-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, and in addition it extracts those files that do not already exist on disk.

-v

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 "unzip -v"), a diagnostic screen is printed.

-z

display only the archive comment.

Modifiers

-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 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.

-b

treat all files as binary (no text conversions).

-B

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.

-C

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!

-D

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.

-j

junk paths. The archive’s directory structure is not recreated; all files are deposited in the extraction directory (by default, the current one).

-K

retain setuid/setgid/sticky file attributes. Without this flag, these attribute bits are cleared for security reasons.

-L

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.

-M

pipe all terminal output through an internal pager similar to the more command.

-n

never overwrite existing files. If a file already exists, skip the extraction of that file without prompting.

-o

overwrite existing files without prompting.

-P password

use password to decrypt encrypted zipfile entries (if any).

-q

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.

-X

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. -d / ). However, when the -: option is specified, it is still possible to implicitly write to the root directory by specifying enough "../" path components within the zip archive. Use this option with extreme caution.

-^

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:

unzip letters

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 extract all C source files and Makefile, regardless of case, into the /tmp directory:

unzip -C source.zip "*.[ch]" Makefile -d /tmp

To extract newer versions of the files already in the current directory and create any files not already there:

unzip -uo sources

Exit status

The exit status (or error level) approximates the exit codes defined by PKWARE and takes on the following values:

0normal; no errors or warnings detected.
1one 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.
2a generic error in the zipfile format was detected. Processing may have completed successfully anyway; some broken zipfiles created by other archivers have simple workarounds.
3a severe error in the zipfile format was detected. Processing probably failed immediately.
4unzip was unable to allocate memory for one or more buffers during program initialization.
5unzip was unable to allocate memory or unable to obtain a tty to read the decryption password(s).
6unzip was unable to allocate memory during decompression to disk.
7unzip was unable to allocate memory during in-memory decompression.
9the specified zipfiles were not found.
10invalid options were specified on the command line.
11no matching files were found.
50the disk is (or was) full during extraction.
51the end of the ZIP archive was encountered prematurely.
80the user aborted unzip prematurely with control-C (or similar)
81testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.
82no files were found due to bad decryption password(s). (If even one file is successfully processed, however, the exit status is 1.)

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