How to Create Zip Files in Linux

How to Create Zip Files in Linux
How to Create Zip Files in Linux

Create Zip Files in Linux

Zip is a utility available for Linux used to compress files or directories without losing the quality of the file. Zip utility supports lossless data compression. Zipped files take less space on your system and can be transferred easily from one system to another. This utility can also be used on Windows, MacOS. In this tutorial, we are going to learn How to create Zip files in Linux.

Install Zip Utility in Linux

You can install zip utility in any Linux distro using the following command:

Install Zip on Ubuntu on Debian

sudo apt install zip

Now Install Zip on CentOS

sudo yum install zip

Install Zip on Ubuntu on Debian

sudo dnf install zip

Install Zip on SUSE/OpenSUSE

sudo zypper install zip

Basic Syntax For Zip Command

Following is the basic syntax for Zip command:

zip [options] [dest_file_name] [files...]

Where,
options : different zip options available here.
dest_file_name : name of the zip file that should be created.
files : files to be zipped

Create a Simple Zip File

You can create a simple zip file with zip command without using any options.

For example to create a zip file of text files first_file.txt, second_file.txt and third_file.txt run below command:

sudo newfile.zip first_file.txt second_file.txt third_file.txt

The output should be:

adding: first_file.txt
adding: second_file.txt
adding: third_file.txt

Create a Zip File of a Directory Contents

You can also create a zip file of all the files in a specific directory with an option -r which traverses the whole directory recursively.

Below is the basic syntax for creating a zip file or directory:

zip -r newfile.zip directory_path_or_sub_directory_name's

For example to zip a subdirectory run below command:

sudo zip -r newfile.zip  subdirectory1

You can also zip multiple subdirectories using below command:

sudo zip -r newfile.zip subdirectory1 subdirectory2

You can also create a zip file using directory path:

sudo zip -r newfile.zip /var/www/

Above command will create the zip file of all the contents inside /var/www/ directory.

Conclusion

You have successfully learned How to Create Zip Files in Linux. If you have any queries please don’t forget to comment out.

LEAVE A REPLY

Please enter your comment!
Please enter your name here