How to Unzip zip files in Linux

In this tutorial, we will talk about How to Unzip zip files in Linux. I will show you step by step unzipping files or folders from the zip file using GUI and Command-line terminal.

Before talking about the unzip program, We need to understand a bit of background on zip utility. Zip is a file packaging and compression utility that is widely used around the world and it acts as a container to keep compressed files or folders.

ZIP is used and installed by default in all operating systems whether it's Linux, Unix, Windows or Mac except few cases.

I will cover all possible important options available and you may require to unzip files in Linux. All files having .zip extension are compress file in Linux.

What is Unzip utility?

Unzip is basically a utility or program to list, test (CRC) and extract compressed files of Zip archive container. it is compatible with two other companions tar and Pkunzip. You may require tar utility to untar files, after unzipping zip files in Linux.

Pre-requisite of unzip utility

The only Pre-requisite of unzip utility is to check whether it's installed or not.

Run this command on the Linux terminal - to get this checked or install unzip program, if it's not there already.

$ sudo apt install unzip

unzip-install-linux

Mine unzip program is already installed, so if you will check in the output it says "unzip is already the newest version".  Many of you will also get the same result as Ubuntu keeps updating software in the background.

if you have some different distro like Centos or Fedora, don't worry, check this command

$ sudo yum install unzip

There are two ways to perform Unzip files in Linux -

  • Graphical user interface (GUI)
  • Command-line (Linux terminal)

Let's start with GUI first, as it gives limited default options of unzip files in Linux, not much freedom to use all listed options.

GUI (Graphical user interface) Technique

How to list files or folder in zip file

Step1:-

Go to the directory where zip files reside.

Step2:-

Select zip file and right-click - open with Archive Manager

open-zip-file-linux

Step3:-

You can see what all files exist in your zip file. I have three files in it.

list-show-files-zip

How to unzip zip files in Linux

Step1:-

Go to the directory where zip files reside.

Step2:-

Select the zip file and right-click on Extract Here.

unzip-file-same-dir
Step3:-
you will see "Directory with the name of zip file" containing all files. In my case, it is the "File" folder because my zip file name is "file.zip"

unzip-folder

Step4:-
Open the folder, check your files and you are done.

How to extract the zip file in the different directory

Step1:-
Go to the directory where zip files reside.

Step2:-
Select the zip file and right-click on the "Extract to" option.

Step3:-
Go to the target directory and validate your files.

Command-line (Terminal) Technique

How to list or show files in a zip file

To list files or folder in zip file, option -l can be used.

$ unzip -l "zip-file-name"

Example

dev@test:~$ unzip -l test.zip

Output
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
0 2020-06-20 21:03 sample/
90082 2020-06-18 18:20 sample/file3
90082 2020-06-17 23:21 sample/file2
90082 2020-06-17 21:51 sample/file1
--------- -------
270246 4 files
dev@test:~$

How to unzip files in Linux command line

It is a straightforward and simplest command. it will extract or unzip all the files in the same directory if you have not given any option.

$ unzip "zip-file-name"

"test.zip" is the file, which I will extract in the same directory.

dev@test:~$ unzip test.zip

Output
Archive: test.zip
creating: sample/
inflating: sample/file3
inflating: sample/file2
inflating: sample/file1
dev@test:~$

One point to note here is, permission on extracted files or folders from unzip command will be owned by the user extracting it and will not inherit permissions assigned during zip creation.

You just require read-write permission on the directory to unzip files or folders in Linux.

How to extract file in the different directory

To extract zip file in the different directory, option -d with "directory-path" will do the trick.

$ unzip "Zip-file-name" -d "/path-to-target-directory"

Example:-

dev@test:~$ unzip test.zip -d /home/dev/diff/

Output
Archive: test.zip
creating: /home/dev/diff/sample/
inflating: /home/dev/diff/sample/file3
inflating: /home/dev/diff/sample/file2
inflating: /home/dev/diff/sample/file1
dev@test:~$

In the output, my target directory is "diff" and all files extracted in "diff" directory.

How to suppress output of unzip command

By-default unzip command prints all files and directory details during extraction. Option -q can be used to suppress these messages.

dev@test:~$ unzip -q test.zip

How to decrypt encrypted zip file

In many cases, files are protected using a password. Option -P followed with the password can be used to decrypt zip files.

$ unzip -P "password" "file-name.zip"

Example:-

dev@test:~$ unzip -P passw0rd test.zip

Output
Archive: test.zip
creating: test/
inflating: test/file3
inflating: test/file2
inflating: test/file1
dev@test:~$

Security warning-

Providing a password in plain text is not advisable. If you won't give -P option, Just type unzip command, then you will have the freedom to enter the password on the terminal.

Example:-

dev@test:~$ unzip test.zip

Output
Archive: test.zip
creating: test/
[test.zip] test/file3 password:
inflating: test/file3
inflating: test/file2
inflating: test/file1
dev@test:~$

How to exclude files while unzip a zip file in Linux

if you want to exclude any specific file during extraction from zip, just use option -x in unzip command.

$ unzip "file-name.zip" -x "file-to-exclude"

Example:-

dev@test:~$ unzip test.zip -x "*.txt"

Output
Archive: test.zip
creating: test/
inflating: test/file5
inflating: test/file4
dev@test:~$

if you will check in output, all files got extracted except files with ".txt" extension.

Replace/Overwrite existing files in unzip command

There may be a scenario when you have completed extracting files and you ran unzip command again in the same archive directory, then unzip command will ask you to replace these files.

Default options you will get to select "[y]es, [n]o, [A]ll, [N]one, [r]ename:"

Example:-

dev@test:~$ unzip test.zip

Output
Archive: test.zip
inflating: test/file1.txt
inflating: test/file2.txt
inflating: test/file3.txt
replace test/file5? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: test/file5
replace test/file4? [y]es, [n]o, [A]ll, [N]one, [r]ename:

Option -o can be used to suppress these messages and will overwrite existing files without asking.

dev@test:~$ unzip -o test.zip

Output
Archive: test.zip
inflating: test/file1.txt
inflating: test/file2.txt
inflating: test/file3.txt
inflating: test/file5
inflating: test/file4
dev@test:~$

How to avoid overwriting files in unzip command

If you have deleted any file or directory from an extracted zip file and you want to restore only those files, option -n can be used. It will instruct unzip the file to skip the extraction of files which already exist in the zip file.

$ unzip -n "zip-file-name.zip"

Example:-

dev@test:~$ unzip -n test.zip

Output
Archive: test.zip
inflating: test/file1.txt
dev@test:~$

How to update the timestamp of the zip file

Option -T can be used to update the timestamp of zip file.

$ unzip -T "file-name.zip"

Example:-

dev@test:~$ unzip -T test.zip

Output
Updated time stamp for test.zip.

How to check Zip file for errors

If you have downloaded file and you want to check zip file for CRC (cyclic redundancy check) errors. Option -t is a saviour in this situation.

$ unzip -t "file-name.zip"

Example:-

dev@test:~$ unzip -t test.zip

Output
Archive: test.zip
testing: test/ OK
testing: test/file1.txt OK
testing: test/file2.txt OK
testing: test/file3.txt OK
testing: test/file5 OK
testing: test/file4 OK
No errors detected in compressed data of test.zip.
dev@test:~$

How to use a wildcard in unzip command

If you have more than one zip file to extract. Wildcard character asterisk(*) can be very useful.

$ unzip "file*.zip"

Example:-

dev@test:~$ unzip "*.zip"

Output
Archive: test.zip
creating: diff/
creating: diff/sample/
inflating: diff/sample/file3
inflating: diff/sample/file2
inflating: diff/sample/file1

How to unzip tar.gz files in Linux

Many times, you may get into a situation when you will be looking for unzip command in Linux for gz files.

Further, these files are archived using tar utility. You can use gunzip utility to extract files inside this. This is going to be a two-step process

First, extract the file using gunzip and if it's archived using tar, then tar "-xvf" is helpful to untar archive file

Example:-

Step1- gunzip your file

dev@test:~$ gunzip test.tar.gz

Step2- untar file

dev@test:~$ tar -xvf test.tar

Output
diff/
diff/sample/
diff/sample/file3
diff/sample/file2
diff/sample/file1
dev@test:~$

How to unzip rar files in Linux.

Not everybody in this world working with Linux, you may get into situations where you got an archive file but the format is ".rar" if you want to extract or unzip rar file in Linux. You need to install unrar utility first.

$ sudo apt install unrar

then run unrar command

$ unrar e "File-name.rar"

and you are done!!

Video tutorial

"How to Unzip zip files in Linux video tutorial. Please like, watch and share"

Final notes

Extracting or unzipping a zip file in Linux is not rocket science, Just need to follow the commands and instructions with your complete focus 🙂

More Info

The man page for help

Please leave your thoughts and comments as feedback