ZIP is one of the most commonly used archiving utility.
In this quick tutorial we'll learn about how to use the unzip linux command to extract zip archives.
For this purpose, you can use either the zip or the tar command to do the same thing, but here we'll focus to the ZIP.
ContentsShow / Hide
Install zip and unzip linux command line tools
By default, the zip/unzip command is not installed on most linux distros. So, you've to install it to use the commands. I've already explained it in a previous tutorial about linux zip command, check that out for more details.
Anyway, here's how to install them on Ubuntu, Linux Mint or any Debian based distos.
sudo apt-get install zip unzip
That's all you need to install on Ubuntu, if you're using Arch Linux, Frdora, opneSUSE, CentOS etc. etc. I'm quite sure that I don't need to tell you how to install them.
Linux unzip files
To extract the ZIP files, you can use the unzip linux command, an example below.
This will extract the contents of the zip file inside the current working directory directory.
To extract a ZIP file located on different directory, you've to use the full path.
And if you need to unzip multiple files at once in Linux, append their names one by one or use the
Enjoy free shipping and One-Day delivery, cancel any time.
unzip archive_1.zip archive_2.zip archive_3.zip
unzip *.zip # To extract all the ZIP files present on a folder
Linux unzip files to specific directory
Many time you'll need to extract the ZIP archives to a specific directory, in that case, you've to use the
-d flag along with the linux unzip command , typical syntax is like below.
unzip -d /path/to/destination/directory /path/to/archive.zip
As an example, have a look at the command below, though it's pretty arbitrary.
unzip -d ../text/ ../Documents/html/IoT_revolution.zip
Extract password protected ZIP files
If your ZIP file is password protected, then you have to use the
-P option with linux unzip command.
unzip -P secret_ password my_archive.zip
A more legible example could be like below,
unzip -P "1t's_s3cr3t" secret_info.zip -d /tmp/secret/
Here read more about how you can password protect zip files.
Listing contents of a ZIP archive
If you need to just look inside a zip file without extracting it, the
-l option is useful.
unzip -l ../Documents/html/IoT_revolution.zip
Archive: ../Documents/html/IoT_revolution.zip Length Date Time Name --------- ---------- ----- ---- 0 2017-09-27 20:15 IoT_revolution/ 150977 2016-02-11 16:40 IoT_revolution/iot_img.jpg 5851 2017-09-22 09:45 IoT_revolution/custom_bg.jpg 7240 2017-09-27 20:15 IoT_revolution/iot_revolution_article.html 48924 2017-09-22 09:50 IoT_revolution/style_min.css --------- ------- 212992 5 files
Excluding specific files while unzipping
After getting an overview of the contents, if you need to unzip a file but want to exclude some specif file, you have to use the
-x flag along with
Let's take the IoT_revolution.zip archive, used in previous example. I want to exclude the images, using the
* wildcard also applies here.
unzip ../Documents/html/IoT_revolution.zip -x *.jpg *.png
Another example, let's assume I want to exclude the style_min.css file of that archive.
unzip ../Documents/html/IoT_revolution.zip -x style_min.css
Extract zip files without preserving full path
If the ZIP file is structured with multiple folders and files, but you want to extract everything under a single directory, then use the
unzip -jq ../Downloads/Andromeda-master.zip
-q option is used to suppress the output of the unzip command.
Well, that's all about how you can use the unzip linux command to extract ZIP files in various way. Have a look here to create and extract 7z files in linux.
These are pretty basic examples, for more details read the man page online, or with the
man unzip command on your PC offline.