• 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 Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install PHP 8.2 on Debian 11
    How to Install PHP 8.2 on Debian 11 Linux February 24, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
© 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