Unzipping is the process of taking a single compressed archive and extracting the files and folders from within. As we already have a zip file, we need to extract the files first, also called uncompressing them.
The command to uncompress a zip file is unzip, as follows:
% unzip --help UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send bug reports using http://www.info-zip.org/zip-bug.html; see README for details. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] Default action is to extract files in list, except those in xlist, to exdir; file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage). -p extract files to pipe, no messages -l list files (short format) -f freshen existing files, create none -t test compressed archive data -u update files, create if necessary -z display archive comment only -v list verbosely/show version info -T timestamp archive to latest -x exclude files that follow (in xlist) -d extract files into exdir modifiers: -n never overwrite existing files -q quiet mode (-qq => quieter) -o overwrite files WITHOUT prompting -a auto-convert any text files -j junk paths (do not make directories) -aa treat ALL files as text -C match filenames case-insensitively -L make (some) names lowercase -X restore UID/GID info -V retain VMS version numbers -K keep setuid/setgid/tacky permissions -M pipe through "more" pager See "unzip -hh" or unzip.txt for more help. Examples: unzip data1 -x joe => extract all files except joe from zipfile data1.zip unzip -p foo | more => send contents of foo.zip via pipe into program more unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
If you encounter the below error while running the unzip command:
unzip: command not found
you may try installing the unzip package as per your choice of distribution.
Distribution | Command |
---|---|
OS X | brew install unzip |
Debian | apt-get install unzip |
Ubuntu | apt-get install unzip |
Alpine | apk add unzip |
Arch Linux | pacman -S unzip |
Kali Linux | apt-get install unzip |
CentOS | yum install unzip |
Fedora | dnf install unzip |
Raspbian | apt-get install unzip |
unzip Command Examples
1. Testing the integrity of the zip File:
$ unzip -t test.zip
If the file downloaded with errors, you should try downloading it again. If no errors were detected in the archive, you can move on.
2. Listing the contents of the zip File:
$ unzip -l test.zip
3. Extract zip file(s) (for multiple files, separate file paths by spaces):
$ unzip file(s)
3. Extract zip files(s) to given path:
$ unzip compressed_file(s) -d path/to/put/extracted_file(s)
4. Extract the contents of the file(s) to stdout alongside the extracted file names:
$ unzip -c file.zip
5. Extract a zip file created on Windows, containing files with non-ASCII (e.g. Chinese or Japanese characters) filenames:
$ unzip -O gbk file.zip