How to zip the directory in linux with command line

In this tutorial we will learn,how to zip the directory in linux with command line.Zip is a compression and file packaging utility for Linux,Unix,Windows and various Operating system. The zip helps to compress and reduce the size of file and directory.To zip a directory,first of all we will check ,do we have zip command installed in Linux system.

Note: For more detailed zip examples with command line, read out this post (How to zip directory in linux explained with examples).

The below command will help to find is zip installed or not.

# which zip   (It will show the absolute path of zip)

In CentOS

# rpm -q zip

In Debian or Ubuntu

$ sudo dpkg -l zip

If you find it is not installed in system then install with given below command.

In CentOS or Red hat
# yum install zip

In Debian or Ubuntu
$ sudo apt-get install zip

After confirmation of installed zip package,now we will zip or compress the directory in Linux system.
Use the given below command.

zip -r GiveAnyName.zip  /path/of/Directory

for eg.
 We have a backup directory in /root/ (i.e /root/backup)

zip -r backup.zip /root/backup

The command will compress the directory with extension .zip .
In above given eg. the compressed file name would be backup.zip

3 thoughts on “How to zip the directory in linux with command line”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.