How to Extract ZIP files on Linux using “Unzip” Command

ZIP archives are a popular method of data compression, frequently utilized in Windows and MS-DOS environments. However, they are not limited to these systems and can be effectively managed in Linux as well.

In this tutorial, we will delve into the process of extracting ZIP files on Linux using the “unzip” command. This command is not only used for extraction but also for listing and testing ZIP files.

For those who are new to Linux or are transitioning from a different hosting environment, this guide will be particularly beneficial. It will provide you with the necessary knowledge to handle ZIP files efficiently, whether you’re working on a dedicated, VPS, or cloud hosting setup.

Checking for the Unzip Command

Before we begin, it’s important to check if the unzip command is already installed on your Linux system. To do this, you can attempt to unzip a file. If the command is not found, it means that the unzip command is not installed on your system.

[root@centos62 ~]# unzip
-bash: unzip: command not found

Installing the Unzip Command

If the unzip command is not installed, you can easily install it using the package manager of your Linux distribution. For CentOS, Fedora, or RHEL, you can use the “yum” command as follows:

[root@centos62 ~]# yum install unzip -y

This command will install the unzip package from the CentOS repository. The “-y” option is used to automatically answer yes to any prompts that may appear during the installation process.

[root@centos62 ~]# yum install unzip -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * rpmforge:
 * updates:
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package unzip.i686 0:6.0-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package           Arch             Version                  Repository                        Size
 unzip             i686             6.0-1.el6                CentOS6.2-Repository             143 k

Transaction Summary
Install       1 Package(s)

Total download size: 143 k
Installed size: 309 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : unzip-6.0-1.el6.i686                                                             1/1

  unzip.i686 0:6.0-1.el6


Extracting ZIP Files

Once the unzip command is installed, you can use it to extract ZIP files. To do this, you simply need to use the “unzip” command followed by the name of the ZIP file you want to extract.

See also  How to Install wget on CentOS 5.7

Unzipping a File to a Specific Directory

unzip /path/to/ -d /path/to/destination/directory

This command will extract the contents of “” to the specified destination directory.

Listing the Contents of a ZIP File

unzip -l /path/to/

This command will list the contents of “” without extracting them.

Testing the Integrity of a ZIP File

unzip -t /path/to/

This command will check “” for errors without extracting it.

Overwriting Existing Files without Prompting

unzip -o /path/to/

This command will extract “” and overwrite any existing files with the same name without prompting for confirmation.

Extracting a Specific File from a ZIP Archive

unzip /path/to/ filename.txt -d /path/to/destination/directory

This command will extract only “filename.txt” from “” to the specified destination directory.

Extracting Multiple Specific Files from a ZIP Archive

unzip /path/to/ file1.txt file2.txt -d /path/to/destination/directory

This command will extract “file1.txt” and “file2.txt” from “” to the specified destination directory.

See also  How to Reset CentOS root Password

Excluding Specific Files when Unzipping

unzip /path/to/ -x file1.txt file2.txt

This command will extract all files from “” except for “file1.txt” and “file2.txt”.

Unzipping a Password-Protected ZIP File

unzip -P password /path/to/

This command will extract “” using the password provided.

Unzipping a File and Restoring Original File Dates

unzip -DD /path/to/

This command will extract “” and restore the original file dates.

Unzipping a File Quietly

unzip -q /path/to/

This command will extract “” quietly, without showing the usual output.

Remember to replace “/path/to/”, “/path/to/destination/directory”, “filename.txt”, “file1.txt”, “file2.txt”, and “password” with your actual file paths, directory paths, file names, and password.

Other unzip options:

[root@centos62 ~]# unzip -h
UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

Commands Mentioned

  • unzip [file] – This command is used to extract the contents of a ZIP file.
  • yum install unzip -y – This command is used to install the unzip package on CentOS, Fedora, or RHEL.
See also  How to Run the .sh File Shell Script In CentOS/RHEL


Managing ZIP files is a common task for webmasters and website administrators. Whether you’re working on a shared hosting environment or managing your own web server, knowing how to extract ZIP files on Linux is a valuable skill.

In this guide, we’ve covered the basics of the unzip command, including how to install it and how to use it to extract ZIP files. We’ve also provided a brief overview of the commands used in this tutorial for easy reference.

Whether you’re using Apache, Nginx, or LiteSpeed, understanding how to manage ZIP files will help you maintain an efficient and organized server environment.

Remember, the key to mastering any new skill is practice. So, don’t hesitate to experiment with these commands and explore their various options and parameters.


Leave a Reply

Your email address will not be published. Required fields are marked *