How to unzip a zip using “unzip” command in Ubuntu 20.04
By default, the unzip command is installed on your Ubuntu PC, but if it is not installed then install it by the command mentioned below:
On my PC it is already installed. You must have some file with “.zip” extension in any directory of your PC. Now, move to directory in which your zip file is present by using the change directory “cd” command:
How to unzip a zip file in the same directory in Ubuntu 20.04
After successful installation of the “unzip” command, you can easily unzip a zip file. You must have some file with “.zip” extension. Follow the syntax mentioned below to extract the zip file:
In the syntax you have to replace [FileName] with the name of your zip file. Like my zip file name is “my_files.zip”, now the above syntax will be:
Now my zip file will be extracted to the Downloads directory as demonstrated in the image below:
How to unzip a zip file in a different directory in Ubuntu 20.04
To unzip a zip file in any directory of our own choice rather than extracting it in the same directory it is present, follow the syntax given below:
In the above syntax replace [FileName] with your zip filename as we did previously and replace directory path with the directory path where you want to extract the zip file. For instance, I want to unzip my_file.zip on desktop, the command would be:
Now my file will be extracted on the desktop:
How to unzip a zip file with suppressed output in Ubuntu 20.04
While extracting a zip file, it displays the names of all files in it and then a description when it is finished. Use the “-q” flag to avoid this:
Like I wanted to unzip “my_files.zip” using “-q” flag, so replace [FileName] in the above syntax with your own zip filename:
How to extract a zip file while excluding files in Ubuntu 20.04
While extracting a zip file, you can only extract the files you required and exclude the other files from the zip file. For this you have to use the “-x” flag with unzip command and space between filenames:
In the above syntax replace [FileName] with your zip filename and “Filename1” and “Filename2” with the names of files you want to exclude while unzipping of your zip file and you can exclude as many files as you want following the syntax.
Here my zip Filename is “my_files.zip” and Filename1 is “file1.txt” and Filename2 is “file2.txt” so syntax will be:
Now we can check the extracted zip file whether the mentioned files are excluded or not:
So, we can see that “file1.txt” and “file2.txt” are excluded during extraction.
How to overwrite the existing extracted file in Ubuntu 20.04
If you are extracting some zip file and it’s extracted version is already present in that directory then it will ask your permission to overwrite that file:
Replace [FileName] with the file filename you want to extract:
Use “-o” flag for overwriting already present extracted zip files without producing a dialogue:
Replace [FileName] with your own filename; my zip filename is “my_files.zip”:
How to list the content of a zip file in Ubuntu 20.04
The “-l” flag is used to list the content of a zip file:
Replace [FileName] with your zip filename, here I am listing the content of the “my_files.zip”:
How to unzip a zip file avoiding overwriting of files in Ubuntu 20.04
Use the “-n” flag to avoid overwriting of files which are already extracted from a particular zip file; follow the below mentioned syntax:
I will be replacing [FileName] with “my_files.zip”:
How to unzip multiple files in a directory in Ubuntu 20.04
If you want to unzip all the zip files from a directory at same time then run the below mentioned command:
You can check the number of zip files in directory by below mentioned command:
Here I am going to extract all the zip files in Downloads:
Conclusion
For compressing several files into the single file at the same location we use zip utility. We need to unzip the zip file to utilize the items in it. In this article we discuss various methods to extract zip files such as extraction of files in the same directory they are present, on different locations of your choice, extraction of multiple files of the same directory etc. This write-up will surely assist you in understanding the unzip command in Ubuntu.