Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

How to Unzip Files in Linux?

Unzip is a utility command that is used to extract the files and directories from a zip file. It can be used to extract single or multiple files and even can extract password-protected files.

In this article, we will learn to use the unzip command with several options and scenarios. So, let's start learning.

Command To Unzip File in Linux

unzip filename.zip

Before starting to unzip, first make sure it is installed on your computer as this is not preinstalled in most of the Linux versions.

So, first, install it by using the following command. This is for Debian/Ubuntu system.

$ sudo apt install unzip

If you are using Centos then use this command to install the unzip utility.

$ sudo yum install unzip

If you are using Fedora then use this command to install the unzip utility.

$ sudo dnf install unzip

How to Unzip Files and Directories?

It is a simple and easy command, just use this command to unzip a zip file in Linux. Make sure the zip file should be in the same directory or you will have to provide a proper zip file path to locate the file.

$ unzip filename.zip

It will extract all the files into the current directory location.

You must have write permissions for the directory where zip is extracting.

Suppress the output of the unzip Command

When we unzip a file then it displays all the file content to the console and if we want to hide/skip this information then you can use -q option with the unzip command.

$ unzip -q filename.zip

Unzip a ZIP File to a Different Directory

If we want to unzip the zip file to a different directory other than the current directory, then use -d option with the command and provide the complete path of the directory.

$ unzip filename.zip -d /path/to/directory

Since we are writing(unzipping) to a different directory then must use sudo with the command because we must have writing permission for the directory.

Unzip a Password Protected ZIP file

If the zip file is password protected then use -p option with the command that will prompt for the password before the unzip.

$ unzip -p filename.zip

Unzip Multiple Files

We can unzip multiple files by using a regular expression to match all the zip files. We can use star(*) wildcard for multiple selections. Like:

$ unzip '*.zip'

It will search for the zip files in the current directory and extract each in the same directory. It is better to use single quotes to bind the wildcard.

Display Content of Zip File

In case, you want to see the zip file content before extracting then use -l option with the command and it will list out all the content of the zip file to the console screen.

$ unzip -l filename.zip

Output:

zip file

Overwrite Existing files

If the unzip file is already extracted and you want to unzip that again then the unzip command prompt for some couple of options like overwrite one file, overwrite all files, etc. To overwrite these, you can use -o option with the unzip command.

$ unzip -o filename.zip

Conclusion

The unzip command is very useful for Linux users. It simplifies the work and provides several options that you can use for multipurpose. In this article, we learned to use unzip with several scenarios like unzip the single file, multiple files, overwrite files, list out zip file content, etc.