How to create a Zip file on Linux
Creating a Zip file on Linux
Zip is a Linux utility used to compress files or directories without compromising file quality. Zip utility supports lossless data compression. Compressed files save space on your system and can be easily transferred between systems. This utility can also be used on Windows and MacOS. In this tutorial, you will learn how to create a Zip file on Linux.
Install Zip utility on Linux
You can use the following command to install the zip utility on your Linux distribution.
sudo apt install zip
Install Zip on CentOS
sudo yum install zip
Installing Zip on Debian Ubuntu
sudo dnf install zip
Install Zip on SUSE / OpenSUSE
sudo zypper install zip
Basic syntax of Zip command
The basic syntax of the Zip command is as follows:
zip [options] [dest_file_name] [files...]
options : Various zip options available here.
dest_file_name : The name of the zip file to create.
files : The file to compress
Create a simple Zip file
You can create a simple zip file with the zip command without using any options.
For example, to create a zip file of a text file
third_file.txt Execute the following command:
sudo newfile.zip first_file.txt second_file.txt third_file.txt
The output looks like this:
adding: first_file.txt adding: second_file.txt adding: third_file.txt
Create a zip file of directory contents
You can also use option to create a zip file of all files in a specific directory
-r Scan the entire directory recursively.
The following 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 compress a subdirectory and execute the following command:
sudo zip -r newfile.zip subdirectory1
You can also compress multiple subdirectories using the following command:
sudo zip -r newfile.zip subdirectory1 subdirectory2
You can also create a zip file using a directory path.
sudo zip -r newfile.zip /var/www/
The above command will create a zip file of all content inside
You learned how to create a Zip file on Linux. If you have any questions, don’t forget to comment them out.