There is no doubt, using Linux by the command-line interface is more simple and easy than GUI. But Most of the users are familiar and habitual with a graphical interface.
They can’t change their habits easily, Why so they can’t switch themselves for using command-line interface in Linux.
Similar to other tasks, It is so easy to unzip a zip file in Linux. In this article, you will learn how to unzip a file in Linux by using commands with single unzip utility. You can also use graphical Interface to extract zip files.
I am using Ubuntu 19.04 and a compressed zip file WordPress in this article you can download this compressed file from here
Let’s talk about how to unzip zip a file in Linux. Unzip utility is used to unzip files.
- What is Unzip command?
- How to list the content of zip file
- How to unzip a zip file in the same directory
- How to unzip a zip file in Different directory
- How to unzip and overwrite existing files
- How to unzip without overwriting existing files
- How to unzip password protected file
- How to unzip multiple zip files in a single command
- How to unzip a file in Linux by using GUI
What is Unzip command?
unzip is utility pre-installed in Ubuntu 19.04 used to extract content from zip compressed files.
If you want to know more about unzipping utility use following command syntax in Ubuntu to check the manual page of unzip command.
Read all pages carefully.
How to list the content of zip file
You are going to extract files but don’t what are contents inside the zip file. You can read content from a zip file without extracting it.
You can see existing content of zip file easily by using the following command.
Use unzip command followed by -l option and name of zip file with .zip extension. You can see an example in the following:
vijay@Ubuntu-19:~/Downloads$ls file_2.txtwordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$unzip -l wordpress-5.2.1.zip Archive: wordpress-5.2.1.zip Length Date Time Name --------- ---------- ----- ---- 0 2019-05-21 23:54 wordpress/ 3068 2018-08-17 07:21 wordpress/xmlrpc.php 369 2017-12-01 04:41 wordpress/wp-blog-header.php 7447 2019-04-09 04:29 wordpress/readme.html 31085 2019-01-16 22:21 wordpress/wp-signup.php 420 2017-12-01 04:41 wordpress/index.php 3847 2019-01-09 14:07 wordpress/wp-cron.php 2898 2019-01-08 10:00 wordpress/wp-config-sample.php 39574 2019-04-16 04:09 wordpress/wp-login.php 18962 2019-03-29 00:34 wordpress/wp-settings.php 19935 2019-01-02 02:07 wordpress/license.txt
You can use | more option for reading line by line contents files.
How to unzip a zip file in the same directory
You have seen content inside the zip file. Now, do you like to extract it?
Yes, It is time to unzip the file. Here is simple text to unzip the file in Linux
If you bother to display a long list of logs on the screen then you can use unzip command followed by -q option. It will extract files silently without showing anything on the screen.
vijay@Ubuntu-19:~/Downloads$ls file_2.txtwordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$unzip -q wordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$ls file_2.txtwordpresswordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$
How to unzip a zip file in Different directory
Don’t you want to extract file in the same directory? Don’t worry! you don’t need a specific skill to do so.
For example, you have downloaded the wordpress zip file in Download folder. But you want to extract in another location. I am going to unzip a file in /home/vijay/Documents directory.
I used the following syntax:
$unzip -q wordpress-5.2.1.zip -d /home/vijay/Documents/
vijay@Ubuntu-19:~/Downloads$unzip -q wordpress-5.2.1.zip -d /home/vijay/Documents/ vijay@Ubuntu-19:~/Downloads$ls /home/vijay/Documents/ file10.txt file11.txt newfile1.txt newfile.txt wordpress vijay@Ubuntu-19:~/Downloads$
I didn’t want to display a long list on the screen. So, I used -q option before the zip file name.
How to unzip and overwrite existing files
When you think about overwriting existing files, one question stuck in your mind.
Why do you unzip file again if you have already?
It is possible everyone has different reasons for this answer. About my story.
I had a WordPress website and it was running pretty good. But after some time, I was getting issues on my client’s website.
I audited and checked security for a WordPress website. I found “website has been hacked and lots of code has been injected in some files?
It was not possible to check code for every file, So I downloaded WordPress core files, Theme, and plugins. Extracted and overwrite all files.
You can use the following command to do the same
vijay@Ubuntu-19:~/Downloads$unzip wordpress-5.2.1.zip Archive: wordpress-5.2.1.zip replace wordpress/xmlrpc.php? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
When you use unzip command followed by file name and unzip files in the same folder where files exist already.
It will ask for overwriting. Press Y if you want to check and replace files one by one. Choose The option for overwriting all files.
Use -o option without prompting your confirmation to overwrite files.
vijay@Ubuntu-19:~/Downloads$unzip -o wordpress-5.2.1.zip
vijay@Ubuntu-19:~/Downloads$unzip -qo wordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$
How to unzip without overwriting existing files
I am working as Linux administrator and unzip a zip file in Linux operating system, Then I handover over the system to the user.
After some time the same user reported some files have been deleted accidentally. I have two options:
One is extracted all the files and overwrite.
If you are thinking same then remember this is a flop idea forever. Because If the user has made some changes in files, will be lost.
Second is extract all the files without overwriting the existing file
Thumbs up for this idea, In this way, Existing files will remain same and deleted file will be restored from the archive.
vijay@Ubuntu-19:~/Downloads$unzip -n wordpress-5.2.1.zip
vijay@Ubuntu-19:~/Downloads$unzip -qn wordpress-5.2.1.zip vijay@Ubuntu-19:~/Downloads$
How to unzip password protected file
Use unzip command followed by -P password for file and filename.
vijay@Ubuntu-19:~/Downloads$unzip -P FilePasswOrd Protectedfile.zip vijay@Ubuntu-19:~/Downloads$
How to unzip multiple files in Linux
Following command can be used to unzip multiple files.
vijay@Ubuntu-19:~/Downloads$unzip -q '*.zip vijay@Ubuntu-19:~/Downloads$
How to unzip file in Linux using GUI
The graphical user interface is very loving and popular interface in worldwide. It has limitations.
Here I am going to extract files in Linux by using the Graphical interface.
The first step opens the folder where zip file exists.
Right-click on the zip file and click on extract here. This option will extract the file in the same folder.
You can see the result in the following the image.
If you want to extract the zip file in a different location then
Right Click on zip file > Extract to
Browse the location where you want to extract content from the zip file and click on select option
The files will be extracted in the selected location.
In this article, you have learned how to unzip a zip file in Linux with multiple options. If you have any question related unzip a file in Linux writes a comment below.