ZIP is one of the most widely used archival, compression formats available. ZIP also supports lossless compression. A ZIP file can be a collection of files or a folder or a mix of both. In this tutorial, we will discuss how we can use the unzip command to manage the zip files. We have already discussed how to create a zip file in the tutorial HERE.

Recommended Read: Linux commands you should never run on your system

Also Read: Essential Linux Commands You Should Know

Let’s discuss how we can use the unzip command in Linux but first let’s discuss its installation.


Install Unzip Command


To install unzip command on centos system, run the following command,

# yum install unzip

To install unzip command on Ubuntu, run the following command,

# sudo apt-get install unzip


Examples of unzip command


List the content of zip file

To get the list of contents inside the zip file, we can use the following command,

# unzip -l filename.zip


Extract the zip file

Most of the time you will need this option only, to extract a file use the following command,

# unzip filename.zip


Extract a password-protected zip

If zip file is password-protected, we can use the option ‘P’ to provide the password & extract it,

# unzip -P password_here filename.zip


Extract file to another directory

Above command extracts the file in the same directory as the zip file but if required, we can also extract the zip file into another directory using the following command,

# unzip filename.zip -d /path_to_extract


Test zip files for errors

To make sure that the zip file is correct & does not have any compression error, we can use options ‘tq’,

# unzip -tq filename.zip


Unzip only deleted or removed files

If some files are deleted from an extracted folder & we require them again. Then we can extract only the files that have been deleted or are unavailable from the zip file by using the option ‘n’,

# unzip -n filename.zip


Exclude file during extraction

What if we don’t want to extract some files from a zip file, we can exclude them with option ‘x’,

# unzip filename.zip -x excluded_file1 excluded_file2 *.txt


That’s it for now for our tutorial on how to use unzip command in Linux. You can write to us for any query, question or suggestion using the comment box below.