How to Unzip Files in Linux

You download a WordPress release, a website theme, or a batch of files a colleague sent from Windows, and it arrives as a .zip file. Before you can use the files, you need to extract them.
ZIP is the most widely used archive file format that supports lossless data compression. A ZIP file is a data container containing one or more compressed files or directories, which can later be extracted to restore the original files. On Linux, you extract them from the terminal with the unzip command.
ZIP archives can also be password protected, which is why unzip may ask for a password before extracting encrypted files.
This article explains how to use the unzip command to extract and manage ZIP archives in Linux.
Quick Reference
| Option | Description |
|---|---|
unzip file.zip | Extract to current directory |
unzip -d /path file.zip | Extract to a specific directory |
unzip file.zip file1 file2 | Extract only the listed files |
unzip -p file.zip file.txt | Print a file to standard output |
unzip -q file.zip | Quiet mode, suppress output |
unzip -o file.zip | Overwrite existing files without prompting |
unzip -n file.zip | Never overwrite existing files |
unzip -j file.zip | Flatten directory structure on extract |
unzip -l file.zip | List archive contents |
unzip -t file.zip | Test archive integrity |
For a printable quick reference, see the ZIP/UNZIP cheatsheet .
Installing unzip
Ubuntu Desktop and Debian with GNOME ship with unzip already installed. Server and minimal installations usually do not include it. If the unzip command is missing on your system, install it using your distribution’s package manager.
Install unzip on Ubuntu, Debian, and Derivatives
sudo apt install unzipInstall unzip on Fedora, RHEL, and Derivatives
sudo dnf install unzipHow to Unzip a ZIP File
In its simplest form, when used without any options, the unzip command extracts all files from the specified ZIP archive to the current directory.
For instance, suppose you downloaded the WordPress installation ZIP file. To unzip this file to the current directory, you would run the following command:
unzip latest.zipZIP files do not store ownership information. The extracted files are owned by the user that runs the command.
You must have write permissions on the directory where you are extracting the ZIP archive.
Suppress the Output of the unzip Command
By default, unzip prints the names of all the files it is extracting, and it will also give you a summary once the extraction process is complete.
To suppress the printing of messages, use the -q option:
unzip -q filename.zipUnzip a ZIP File to a Different Directory
If you want to extract the contents of a ZIP file to a directory other than the present working directory, you can use the -d option. This allows you to specify the path of the destination directory where you want to extract the files.
unzip filename.zip -d /path/to/directoryFor example, to unzip the WordPress archive latest.zip to the /var/www/ directory, you would use the following command:
sudo unzip latest.zip -d /var/wwwIn the command above, we are using sudo
because the user we are logged in as typically does not have write permissions to the /var/www directory. When ZIP files are decompressed using sudo, the extracted files and directories are owned by the user root.
If the destination directory does not exist, unzip creates it. However, it creates only the last directory in the path. When a parent directory is missing too, the command fails:
unzip latest.zip -d newdir/nestedArchive: latest.zip
checkdir: cannot create extraction directory: newdir/nested
No such file or directoryCreate the full path first with mkdir -p
, then run unzip again.
Unzip a Password Protected ZIP File
If you have a ZIP file that is protected with a password and you want to extract its contents, you can use the unzip command with the -P option. This option allows you to specify the password required to open the file. Once you enter the correct password, the contents of the ZIP file will be extracted to the current directory.
unzip -P PasswOrd filename.zipTyping a password on the command line is insecure and should be avoided. A more secure option is to run the command without using the -P option.
If the ZIP file is password protected and you do not use -P, unzip will prompt you to enter the password:
unzip filename.zipType the password and press Enter.
Archive: filename.zip
[filename.zip] file.txt password:unzip will use the same password for all encrypted files in the archive as long as it is correct.
Test a ZIP File Without Extracting
To test a ZIP archive for errors without extracting it, use the -t option:
unzip -t filename.zipExclude Files when Unzipping a ZIP File
When you want to exclude specific files or directories from being extracted from an archive, use the -x option, followed by a list of the archive files you want to exclude from the extraction process, separated by spaces.
unzip filename.zip -x file1-to-exclude file2-to-excludeIn the following example, we are extracting all files and directories from the ZIP archive except the .git directory:
unzip filename.zip -x "*.git/*"Overwrite Existing Files
Suppose you have already extracted a ZIP file and run the same command again.
unzip latest.zipBy default, unzip asks whether you want to overwrite only the current file, overwrite all files, skip extraction of the current file, skip extraction of all files, or rename the current file.
Archive: latest.zip
replace wordpress/xmlrpc.php? [y]es, [n]o, [A]ll, [N]one, [r]ename:If you want to overwrite existing files without being prompted, use the -o option:
unzip -o filename.zipUse this option with caution. If you previously made any changes to the files, the changes are lost. In automation, -o is convenient, but it can overwrite files silently.
Unzip a ZIP File Without Overwriting Existing Files
Suppose you have unzipped a ZIP file and modified some of its files. However, you mistakenly deleted a few files that you now need to recover from the ZIP archive. What you want to do now is to restore the deleted files from the ZIP archive while keeping the changes you have made.
In this scenario, use the -n option, which instructs unzip to skip the extraction of a file if it already exists in the target directory:
unzip -n filename.zipUnzip Multiple ZIP Files
You can use wildcard patterns to match multiple archives.
For instance, if you have multiple ZIP files in your current working directory , you can unzip all files using only one command:
unzip '*.zip'Note the single quotes around *.zip. If you forget to quote the argument, the shell expands the wildcard before unzip runs. unzip then treats the first file as the archive and the other files as names to extract from it:
Archive: archive1.zip
caution: filename not matched: archive2.zipNothing is extracted in this case. Add the quotes and run the command again.
List the Contents of a ZIP File
To list the contents of a ZIP file, use the -l option:
unzip -l filename.zipIn the example below, we are listing all WordPress installation files:
unzip -l latest.zipThe output will look like this:
Archive: latest.zip
Length Date Time Name
--------- ---------- ----- ----
0 2023-08-02 22:39 wordpress/
3065 2021-08-31 18:31 wordpress/xmlrpc.php
364 2021-12-19 12:20 wordpress/wp-blog-header.php
7415 2023-03-18 17:13 wordpress/readme.html
...
...
21323 2023-03-09 01:15 wordpress/wp-admin/themes.php
8353 2022-09-10 18:20 wordpress/wp-admin/options-reading.php
4620 2021-10-24 00:12 wordpress/wp-trackback.php
1889 2023-05-03 00:11 wordpress/wp-comments-post.php
--------- -------
27271400 1648 filesTo show a more detailed listing, use -v:
unzip -v filename.zipExtract Specific Files from a ZIP Archive
You do not always need the whole archive. To extract only certain files, pass their names after the archive name:
unzip latest.zip wordpress/wp-config-sample.phpArchive: latest.zip
extracting: wordpress/wp-config-sample.phpThe name must match the path stored in the archive, including any leading directories. If you type only wp-config-sample.php, unzip prints caution: filename not matched and extracts nothing. When you are not sure how a file is stored, list the archive first with unzip -l.
To extract a whole directory from the archive, use a wildcard pattern. Quote it so the shell does not expand it:
unzip latest.zip "wordpress/wp-content/*"The extracted files keep their directory structure. The command above creates wordpress/wp-content/ in the current directory.
Flatten Directory Structure When Extracting
By default, unzip recreates the directory structure stored inside the archive. If you want all files extracted into a single flat directory without any subdirectories, use the -j (junk paths) option:
unzip -j filename.zipThis is useful when you only need the files themselves and do not care about the original folder layout inside the archive.
Troubleshooting
A few errors come up often when extracting ZIP archives. Here is how to recognize and fix them.
unzip: command not found
The unzip package is not installed. Install it with your package manager as shown in the Installing unzip
section above.
End-of-central-directory signature not found
This usually means the archive is incomplete or corrupt, most often from an interrupted download. Download the file again, then verify it before extracting with unzip -t filename.zip.
skipping: filename unsupported compression method 99
Method 99 is AES encryption, which the standard unzip utility cannot decrypt. Depending on the tool that created the archive, the message can also read need PK compat. v5.1 (can do v4.6). Extract the archive with 7z
instead: 7z x filename.zip.
warning [archive.zip]: zipfile claims to be last disk of a multi-part archive
The archive was split into parts such as archive.z01 and archive.z02, and unzip cannot extract split archives directly. Place all parts in the same directory, join them with zip -s 0 archive.zip --out joined.zip, and then run unzip joined.zip.
Conclusion
unzip
is a command-line tool that allows you to list, test, and extract compressed ZIP archives.
To create a ZIP archive on a Linux system, use the zip command
. For .tar.gz and other compressed tarballs, see how to extract a tar.gz file
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page