How to extract a zip file to a folder in Linux? Step by step command with example to extract a zip to specified folder
In this tutorial we are going to explain you the usage of unzip tool in Linux and tell you the command to extract content of a zip file to a specified directory. If you have a zip file and you want to extract to a specified folder instead of extracting to same folder then you can easily use the unzip command of Linux. There are many ways you can use this command to extract a zip file.
This tutorial will explain you how to install unzip utility in your Linux box if its not there and then use the unzip command to extract a zip file to directory of your choice.
What is unzip utility?
The unzip utility is a command line tool for Linux operating system which can be used to unzip a zip file. In Ubuntu operating system you can install it with following command:
sudo apt install unzip
Above command will ask you the admin password and after that it will install unzip tool on your Ubuntu operating system.
If you are using Centos or Redhat Linux then use the following command to install on your system:
sudo yum install unzip
The yum utility will install unzip tool on your system.
How to use unzip tool?
In many different way you can use the unzip tool to unzip your files. Here is the syntax of unzip utility:
unzip file.zip
Above command takes zip file name as parameter and then extracts the content of this file into current directory.
If you want to extract the content of a zip file to a specified directory then you can use -d option. With -d option you can specify the directory where you want to extract the content of file. Here is syntax:
unzip -d /myuser/mydirectory/ file.zip
Above command will extract the content of file.zip into /myuser/mydirectory/. So, extract the content to a specific directory you can use unzip command.
Here is the screen shot of use use of unzip command to extract content to a different directory:
Example of extracting zip file into a directory
Suppose you have a file file.zip and you want to extract the content of this file into a directory called extractdir. Then you can use the following command:
unzip file.zip -d extractdir
You can also provide the complete path of the directory if the directory is in different path than the current directory. Here is example:
unzip file.zip -d /home/user/somedir/extractdir
Here is the screen shot of the unzip example in Ubuntu 18.04:
In this tutorial we have learned how to use the unzip tool to zip a file.
Related Linux tutorials: