• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Unzip Files in Linux

Written by Admin, Updated On July 27, 2019
terminal, unzip
How to Unzip Files in Linux

ZIP is the most popular and widely used to compress files and directories without losing the quality of the file. It is a container which containing single or multiple compressed files or directories. In this tutorial, you will learn how to unzip files and directories in Linux systems using unzip utility.

Install Unzip#

Unzip is a utility that helps you list, test and extract compressed ZIP archives.

Install Unzip on Ubuntu and Debian#

sudo apt install unzip

Install Unzip on CentOS and Fedora#

sudo yum install unzip

How to Unzip File in Current Directory#

If you wants to unzip the compressed files in current directory then it’s very simple. Remember, you should preserve ownership and write permission for current directory.

unzip bkpfile.zip

The above command will unzip the bkpfile.zip file to the current directory and saves extracted files.

Unzip Files in Specific Directory#

If you wants to extract zip file to a specific directory then you can pass -d option along with unzip command. It must required write permission for a given specific directory so it is recommended that to run it with sudo.

For example, we have a file named bkpfile.zip and wants to extract at /var/www/html directory then you should run below command:

sudo unzip bkpfile.zip -d /var/www/html/

How to Unzip File with Password#

When your zip file contains sensitive information then it is compressed using password. So you can extract password protected file using unzip command. Below is the syntax to unzip using password:

sudo unzip -P PASSWORD bkpfile.zip

Where, PASSWORD should replace with the password of your zip file.

For example, your zip named bkpfile.zip is password protected and your password is xyz#123 then you can unzip using below command:

sudo unzip -P xyz#123 bkpfile.zip

Exclude Files when Unzipping a ZIP File#

When you have need to extract all the files from ZIP file except any one or multiple then you should use -x switch.

unzip filename.zip -x file-to-exclude

For below example, we are extracting all files and directories from the ZIP archive except the .git directory:

unzip bkpfile.zip -x ".git/"

How to Overwrite Existing Files when using Unzip#

Once you have extracted a zip file and you execute same command again then what should happen? By default, unzip will ask you whether you would like to overwrite all file, skip extraction of the current file, skip extraction of all files, or rename the current file.

Archive:  bkpfile.zip
replace server.php? [y]es, [n]o, [A]ll, [N]one, [r]ename:

If you are sure from first and want to overwrite file then you can use -o switch as below:

unzip -o bkpfile.zip

Note: If you have made changes in old files and you overwrite then you will lost changes.

How to Unzip Multiple ZIP Files#

If you have multiple ZIP files in your current working directory you can Unzip all files using only one command:

unzip '*.zip'

It will extract all the zip files in current directory.

Conclusion#

You learned how to Unzip archives using the unzip command. To create a ZIP archive on a Linux system, use the Zip command.

If you have any question or suggestion, please leave comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install PostgreSQL on Debian 10
Next Article   How to Install R on CentOS 7

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP on Debian 10
    How to Install GIMP 2.10 on Debian 10 December 27, 2020
  • How to Install GIMP 2.10 on CentOS 8
    How to Install GIMP 2.10 on CentOS 8 December 30, 2020
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook