ZIP files are a universal archive commonly used on Windows, macOS, and even Linux systems.
You can create a zip archive or unzip files from one with some common Linux terminal commands.
The .zip extension is used for the compressed file format.
This format allows you to compress all files of a directory without any data loss. Users can compress more than one directory or file at a time using Zip file format.
However, when you want to extract the zip files in Linux distribution, you need to use a command-line utility that is known as 'unzip command'.
You can easily extract all types of zip files just in a few minutes using this command-line tool.
In this context, we shall look into how you can unzip files through the terminal in a Linux environment.
We have implemented the unzip command on the CentOS 8 system.
These commands are the same for all Linux distributions, therefore, you can implement all these commands on Ubuntu, Debian, LinuxMint and fedora, and so on.
How to Use of unzip command in File Extraction ?
The unzip command is not installed on CentOS 8.
But, it is preinstalled on most of the Linux distributions.
Open the terminal window from the left sidebar of your desktop in CentOS 8 and install this utility by using the following command:
# yum install unzip
How to perform File Extraction using unzip command ?
You can easily extract a zip file by using the unzip command.
Using the below-given command, you can unzip a file into a current folder or directory:
# unzip file-name
For example, if you want to extract a zip file 'text.zip' into the current directory 'Downloads' then, navigate into the 'Downloads' folder and list all files.
Now, use the following command to unzip a file:
# unzip text.zip
How to Extract file into another directory ?
If you want to extract a zip file into another directory then, Use the -d option with the unzip command.
To extract a file into a different directory, type the below-mentioned command on the terminal:
$ unzip file-name.zip -d /directory-path
For example, you want to extract a zip file in the Documents instead of extracting it into the current Downloads.
So, in this case, the following command will be used:
# unzip test.zip -d /home/Documents/
How to Unzip files with suppressing output ?
During the extraction of a file, it first prints the file names and also shows a summary of task completion.
If you don't want to print all file names then, use the option '-q' with the unzip command as follows:
# unzip -q test.zip
Note: The 'text.zip' is the name of a zip file. You can replace your own file name.
How to Exclude file while extracting a ZIP file ?
Using the '-x' option with the unzip command, you can also exclude files and directories from extraction.
Use the following command to exclude a file while extracting a file:
# unzip file-name.zip -x exclude-name1 exclude-name 2
For example, we want to exclude the 'app' folder from the file extraction.
So, the above command will change into the following form:
# unzip test.zip -x "*app*"
How to Overwrite the existing extracted files ?
If you have completed the extraction of a file and again type the unzip command then, it will ask you to overwrite or rename an existing file.
If you want to ignore this prompt then, type the following unzip command with option -o:
# unzip -o test.zip
Use the above-command carefully, due to any small mistake you can lose all your original data.
If you don't want to overwrite these existing files then using the option '-n', you can forcefully skip all these files which have been extracted or exist:
# unzip -n test.zip
How to Unzip multiple files ?
You can also extract multiple files using the unzip command as follows:
# unzip '*.zip'
How to List zip file contents ?
By using the following command, you can list the contents of a zip file:
# unzip -l myfile.zip