ZIP extension is the most widely used file format that is used for data compression without data loss. In a ZIP file, the user can compress more than one directory and compressed files. Therefore, users need to extract these ZIP files with some command-line tool or utility. On a Linux system, using the unzip command users can easily deal with all kinds of ZIP files.
In this article, you will learn how to extract ZIP files via command line on Linux system using unzip command utility. We have run some useful decompression commands on Ubuntu 20.04 system given below: How to use unzip command in Ubuntu 20.04
? The unzip command is already installed on my
But if this is not installed on your Linux system, you can easily install it on your system.
To install the unzip command, open the terminal window
using Ctrl + Alt + t and type
the following command on the terminal screen:
Extract ZIP file with unzip command With the
simple unzip command
, you can extract all files from the zip archive to the current zip file directory as follows:
For example, we have downloaded a zip file in ‘Downloads’ with the name ‘testfile.zip’. So, first, navigate to the Downloads directory and then we have extracted the zip file using the following command:
the file to another directory
Using the -d switch with the unzip command, you can extract the file to a different location instead of the current directory. The basic syntax is as follows:
For example, we want to extract a zip file to the desktop instead of the current downloads. So, we use the following command to do this:
As you can see in the image below, the folder has been extracted to my desktop. You must have read and write permissions to extract a ZIP file to different directories.
Extract ZIP files with output suppression
When you extracted a zip file, it first prints the name of all the files during extraction and also displays a summary upon completion. Using the ‘-q’ switch with the unzip command, you can avoid printing these messages in the terminal as follows:
For example, we have extracted a ‘testfile.zip’ using the ‘-q’ switch. You can see that the zip file is extracted without printing file names.
Exclude files from extracting
a ZIP file
You can exclude directories and archives while unzipping a zip file. Use
the ‘-x’ switch with the unzip command and the name of the excluded files separated with space as follows:
For example, we want to exclude the directories ‘wp-content’ and ‘wp-admin’ in the extraction
Overwrite existing unzipped files
If you have already unzipped the file and will run the command again as follows:
In this case, it will prompt you to overwrite the
existing unzipped file shown in
the following output: <img
src=”https://linuxhint.com/wp-content/uploads/2020/06/7-41.png” alt=”” />
To overwrite existing files without generating a message, you will use the ‘-o’ option with the unzip command as follows:
Use this command carefully because due to any error you may lose your original data.
src=”https://linuxhint.com/wp-content/uploads/2020/06/8-40.png” alt=”” /> Contents of the
zip file list
-l’ option with the unzip command is used to enumerate the contents of a zip file as follows:
In the following example, we have enumerated the contents of ‘testfile.zip’.
If you don’t want to overwrite existing files or accidentally delete some extracted files. Then, you can use the ‘-n’ option with the unzip command that will forcibly skip the extraction of those files that are already extracted or exist.
Using regular expressions, you can decompress multiple matching archive files in the current directory. To
unzip multiple files, you will use the following command in the terminal:
In the following image, you will see that it will extract all zip files from the current working directory.
How to unzip password-protected files? You can also unzip password-protected zip files using the
unzip command as follows:
Opening password-protected files using the command line is not safe. Therefore, it is best to avoid it.
In this article, you learned the uses of unzip command which is very useful for enumerating and extracting the ZIP files. I hope this article will be useful to you in the future.