Zip is an archive file format that supports lossless data compression. It is available for various platforms. Windows and macOS and many other OS are providing built-in zip support. These files generally use
.ZIP file extension. A zip tool allows you to specify the compression level from 1 to 9.
I already discussed creating a zip archive in an article. Today in this article, we will discuss extracting or unzipping a zip file in Linux.
How to Install unzip?
Unzip command is used to list, test, and extract the
.zip files in Linux. It also comes preinstalled in many Linux distributions but if it is not in your system then use one of the below commands –
Debian Based Ubuntu, Linux Mint, etc:
If you are using a Debian based distribution such as Ubuntu, Linux Mint, etc. then use –
sudo apt-get install unzip
RPM-based CentOS, RedHat Linux, etc:
If you are using a system that uses yum package manager then use –
sudo yum install unzip
To install it in fedora use –
sudo dnf install unzip
How to list the files and directories inside a zip file?
To display the list of files and directories inside a zip file named sample.zip you could use the following command in the terminal –
unzip -l sample.zip
Here you can see the listed files and directories along with some other information.
How to unzip a zip archive?
In its simplest form, this will extract the files and directories inside a directory with the same name as a zip file has. Suppose we have sample.zip in the home directory of my system. To extract files from this zip file I will use the following command in the terminal –
How to extract a zip archive into a specific directory?
If you want to extract/unzip a zip archive into a specific directory then use the following steps –
Create a directory if not created already by using –
The above command will create a directory named extracted_files inside the current working directory. Now to unzip the content of zipped file inside the created directory, use the following command –
unzip sample.zip -d extracted_files
How to extract a password-protected zip file?
Suppose we have a zip file sample.zip which is password protected. If you want to extract it then use the following command and enter the password if prompted.
This will extract all the files and directories inside a directory named sample.
Now if you want to explore more options that can be used with the unrar command then see its manual page. To see the manual page, use the following command in the terminal –
If you have any thoughts related to this article, share it with us in the comments below.