Zip command in Linux is used for compressing files & folders to reduce their size for the purpose of archival, backup, or for file transfer. Zip command can compress single or multiple files and folders into a single compressed file with extension .zip. We can also compress the whole operations system/file structure into a compressed file.

Recommended Read: Essential Linux Commands You Should Know

Also Read: Introduction to Bash Scripting Tutorial

Let’s first discuss how we can install ZIP utility on our systems.


To install zip on your system, use the following commands,


# dnf install zip


# yum install zip


$ sudo apt-get install zip

Syntax for using zip command


Now let’s discuss some examples for using zip command.

Examples of zip command


Create a zip file

To create a compressed zip file for files or folders, use the following command,

# zip test.txt test2.txt *.html

Zip a directory

To create zip file for a complete directory with all the files and folders inside, we can use the following command,

# zip -r test_folder

Create a password-protected zip file

To create a zip file that is protected with a password, we can use the following command,

# zip -e test.txt test2.txt *.html

You will then be asked to enter a password to protect the zip file.

Add files to a zip file

To add new files or update existing files to a created zip file, we can use the option ‘u’,

# zip -u new_file.txt

If the file already exists on the zip, then the old file will be overwritten.

Delete a file from zip file

If we wish to remove a file from already created zip, then we can use the option ‘d’,

# zip -d file1.txt

Delete original files after zip creation

We can also make zip command to delete the original files from which the zip file was created by using the option ‘m’,

# zip -m test.txt test2.txt *.html

Using compression level in zip

Zip provides compression level from 0 to 9 with 0 being no compression at all & 9 being the most compressed, default compression is 6. We can mention the compression level as follows,

# zip -8 test.txt test2.txt *.html

Splitting zip file based on size

By default, a single zip file is created but we can also create multiple zip files i.e. splitting zip files based on the size of zip file. For example, we can create zip file with a zip file being a maximum of 2 GB with the help of the following command,

# zip -s 2g test.txt test2.txt *.html

These were some examples of using zip in Linux. Please do let us know your suggestions, question or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.