In this article, we are going to show you that how to Zip Files and Directories in Linux operating system using the zip
command.
In the Linux, ZIP is a archive file format that is used to compress files and directories without losing the quality of the file and directories. Zip supports the lossless data compression. A Zip file is a single file that is containing one or more compressed files or directories.
zipping a file or folder is an ideal way to makes larges files into smaller and it is keep all related files together. Zip method is basically used to transferred zipped files from one to another machine because a compressed (zipped) file take less disk space than uncompressed file.
Install Zip in Linux
zip
utility is not installed by default in most of Linux distributions, so you need to install it using the package manager of your distribution.
Install Zip utility on Ubuntu and Debian
$ sudo apt install zip
Install Zip utility on CentOS and Fedora
$ sudo yum install zip
Syntax of Zip Command
In the Linux, the basic syntax of the zip
command is show as below:
zip [options] ARCHIVE_NAME FILES
How to create ZIP Files and Directories in Linux
To Zip one or more files, run the below command :
$ zip archive_name.zip file1 file2 file3
If you want compress a whole directory including content of subdirectories. Then you can use -r
option to traverse the whole directory structure recursively. So simply use below command to do that :
$ zip -r archive_name.zip directory_name_or_path
If you want to add multiple files and directories in the same archive then use below command to do that :
$ zip -r archive_name.zip directory_name1 directory_name2 file1 file2
Creating a Password Protected ZIP file
If you have sensitive information and want to create a password protected zip file then you can encrypt it using the -e
option, run below command to do that :
$ zip -e archive_name.zip directory_name_or_path
When you run above command, you will be prompted to enter and verify the archive password:
Output
Enter password:
Verify password:
Creating Split Zip File
You can create a split Zip file using the -s
option followed by specified size. The multiplier can be k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes).
$ zip -s 1g -r archive_name.zip directory_name_or_path
The above command will give the below output:
Output
archive_name.zip
archive_name.z01
archive_name.z02
archive_name.z03
archive_name.z04
The above command is helpful if you want to store zipped file on a hosting service and there is file upload size limit.
That’s all
If you face any error and issue in above steps , please use comment box below to report
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.