• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Zip Files and Directories in Linux

Written by Admin, Updated On January 9, 2020
terminal, zip
How to Zip Files and Directories in Linux

ZIP is the most popular and widely used to compress files and directories without losing the quality of the file. It supports lossless data compression. Archieved (zipped) files take less disk space on your system and can be transferred easily and faster from one system to another. ZIP files can be easily extracted in Windows, macOS, and Linux using the utilities available for all operating systems. In this tutorial, you will learn How to zip files and directories in Linux.

Install Zip Utility in Linux#

The zip utility is not installed by default in most Linux distributions, but you can easily install it using the package manager of your distribution.

Install Zip on Ubuntu and Debian#

sudo apt install zip

Install Zip on CentOS and Fedora#

sudo yum install zip

Syntax of Zip Command#

Following is the basic syntax for Zip command:

zip [options] [file_name] [files…]

Where,

  • options : You can pass different zip options.
  • file_name : Name of the zip file which you are creating.
  • files : Files which need to be zipped

How to ZIP Files and Directories in Linux#

You can create a simple zip file with zip command without passing any options. You just have to pass file names with space separated as given below:

zip bkpfile.zip file_name1 file_name2 file_name3
adding: file_name1
adding: file_name2
adding: file_name3

In above output you can see that it will print file names which are added to zip file.

Generally, we have need to compress a whole directory including content of subdirectories. The -r option allows you to traverse the whole directory structure recursively. Use below command to use create a zip of a directory:

zip -r bkpfile.zip directory_name_or_path

You can also add multiple files and directories in the same archive:

zip -r bkpfile.zip directory_name1 directory_name2 file_name1 file_name2

Creating a Password Protected ZIP file#

If you have private information that needs to be stored in the archive you can encrypt it using the -e option:

zip -e  bkpfile.zip directory_name_or_path

It will prompt you to enter and verify the archive password:

Enter password:
Verify password:

Creating Split Zip File#

When you have large amount of files and directories and want to make zip of them then it’s difficult to manage a large single zip file. Instead of that you can split zip files using -s option followed by size.

For example you have data of 7 GB and want to split in 1gb of each then run the below command to split in multiples:

zip -s 1g -r bkpfile.zip directory_name_or_path

It should return the below output:

bkpfile.zip
bkpfile.z01
bkpfile.z02
bkpfile.z03
bkpfile.z04
bkpfile.z05
bkpfile.z06
bkpfile.z07

This option is helpful when you want to upload file somewhere and there is file upload size limit.

Conclusion#

You learned how to create ZIP archives using the zip command. To extract a ZIP archive on a Linux system, you can use the unzip command.
You can get more details about Zip at the Zip Man page. If you have any question or suggestion, please leave comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to List Installed Packages on CentOS
Next Article   Curl Command in Linux with Examples

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP on Debian 10
    How to Install GIMP 2.10 on Debian 10 December 27, 2020
  • How to Install GIMP 2.10 on CentOS 8
    How to Install GIMP 2.10 on CentOS 8 December 30, 2020
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook