How to Unzip Files in Linux operating system

How to Unzip Files in Linux

In this article, we are going to show you that how to Unzip Files in Linux using the unzip command. if you want learn how to unzip files in Linux then this post is ideal for you.

In the LinuxZIP is a archive file format that is used to compress files and directories without losing the quality of the file and directories. Zip supports the lossless data compression. A Zip file is a single file that is containing one or more compressed files or directories.

zipping a file or folder is an ideal way to makes larges files into smaller and it is keep all related files together. Zip method is basically used to transferred zipped files from one to another machine because a compressed (zipped) file take less disk space than uncompressed file.

Install Unzip in Linux


unzip utility is not installed by default in most of Linux distributions, so you need to install it using the package manager of your distribution.

Install unzip utility on Ubuntu and Debian

$ sudo apt install unzip

Install unzip utility on CentOS and Fedora

$ sudo yum install unzip

Unzip File in Current Directory

If you want to unzip a zipped file in the current directory then use the unzip command without any option. You must have write permissions of the directory where you want extracting the ZIP file.

Simply run the below command to unzip a specified ZIP archive:

$ unzip archive_name.zip

When you run the above command, it will unzip the archive_name.zip file in the current directory.


Unzip File in a Different Directory

If you wants to extract a zip file in a different directory then you can use -d option with unzip command.

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

For a example, we are extract a archive file named backup.zip to the /var/www/ directory. To do that run below command :

$ sudo unzip backup.zip -d /var/www

In the above command, we use sudo because the user we are logged in as doesn’t have write permissions of the specific directory where you want extracting the ZIP file so you must run the command with sudo.


Unzip a Password Protected ZIP file

To unzip a password-protected file, run the unzip command with the -P option followed by the password:

$ unzip -P Password archive_name.zip

You can also unzip a password-protected file using unzip command without any option :

$ unzip archive_name.zip

When you run the above command and the zip file is password-protected, then unzip command will prompt you to enter the password:

Output

archive:  archive_name.zip
[archive_name.zip] file.txt password: 

Exclude Files when Unzip a ZIP File

Use the -x option to exclude files or directories from being extracted.

$ unzip archive_name.zip -x filename_to_exclude

For a example, we extracting all files and directories from the zip file named archive_name.zip except the .git directory:

$ unzip archive_name.zip -x "*.git/*"

Unzip Multiple ZIP Files

If you want to unzip multiple ZIP files available in your current directory then run below command to do that :

unzip '*.zip'

The above command will extract all the zip files in your current working directory.


That’s all

If you face any error and issue in above steps , please use comment box below to report

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top