How to install zip/unzip package in Linux CentOS/RHEL 7 and 8

Most PC users, whether familiar with Unix or not, know about Zip files. The zip command offers compression that is based on the algorithm from the PC standard PKZip program. The zip and unzip programs work exactly as you might expect them to: zip [filename] to compress a file with zip, and unzip [filename.z] to unzip the files.

Syntax:

# zip [options] zipfile [files]

Example:
To create a compressed file named mail.zip that contains all the files in the /etc/mail directory, use the following format:

$ zip mail /etc/mail*
  adding: etc/mail/ (stored 0%)
  adding: etc/mailcap (deflated 53%)
  adding: etc/mailman/ (stored 0%)
  adding: etc/mail.rc (deflated 49%)

The following table details some important options:

Option Description
-d Decompress the file (you can also use the unzip command). Note that the zipped file is not deleted.
-v Verbose: Display percentage of compression.
-u Update a .zip file with new content.
-r Zips recursively, meaning you can specify a directory, and all of the contents in that directory (including all subdirectories and their contents) will be zipped.
-x file(s) Specify file(s) to be excluded from the .zip file.

Check if zip/unzip is already Installed

Run the following command to check zip and unzip utility is installed or not:

# rpm -q zip unzip
package zip is not installed
package unzip is not installed
#

Install zip/unzip

If you find it is not installed in system then install with following command:

# yum install zip unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
.......
Installed:
  unzip.x86_64 0:6.0-16.el7                                                     
  zip.x86_64 0:3.0-11.el7

Complete!
#

Verify Installation

Use the following commands to verify the installation:

# rpm -q zip unzip
zip-3.0-11.el7.x86_64
unzip-6.0-16.el7.x86_64
# which zip unzip
/bin/zip
/bin/unzip
#

Zip/unzip is installed on the system and zip command is available to zip a directory!!!

Related Post