The zip file behaves as a container that is composed of more compressed files or folders. There are more file formats such as .tar extension, also common practice to use for Linux systems, but still zipping folders using .zip extension is ubiquitous and a perfect choice.
Using Zip file format for file compression takes less disk space and saves the network bandwidth while you transfer a file from one machine to another system. Zipped file format can be transferred more quickly as compared to uncompressed files. These compressed zip folders can easily be extracted using supportive utilities in Linux, macOS, and Windows operating systems.
You will learn in this guide how to zip a folder in Ubuntu Linux operating system. We will explain two methods for zipping a folder; one method is zip a folder using command-line and the other using the Gnome graphical interface environment. All steps we will cover in this article have been implemented on Ubuntu 20.04 LTS focal fossa distribution.
Method 1: Zip folder using the Terminal or command-line method
Before going into the details, ensure that the zip command-line utility is installed on your system to zip a folder.
Install zip command-line utility
The ‘zip’ is a command-line utility that helps you in file compression. In most Linux distributions, this zip utility is not installed by default. So, if this utility is not available on your Ubuntu distribution, then you can easily install it by using the Ubuntu official apt repository. To install the ‘zip’ command on the Ubuntu system, use the below-mentioned command on the terminal:
$ sudo apt install zip
After installing the zip utility, check the installed version by using the following command:
Zip a folder using the zip utility
To zip a folder through the command line, use the follow the following syntax:
Example
For example, we want to zip a folder ‘MyDocsFolder’. The following command will create a zip archive of this folder:
The folder contents and compression method will print on the terminal that verifies all files have been successfully compressed via zip utility and added to the .zip archive.
Zip multiple folders using the Zip utility
You can add multiple directories or folders into a single zip archive. Similarly, you can also include multiple files in the same archive. Using the following command, you can create a zip archive of multiple files and folders:
$ zip -r MyDocsFolder.zip MyDocsFolder PersonalFolder file1.txt file2.txt file3.txt
Zip compression methods
Zip utility uses various compression methods. The two most commonly used compression methods are store and deflate.
Deflate: The default compression method of zip command is ‘deflate’.
Store: If the zip utility finds a file that can be compressed, it simply includes it into the zip archive without compression using the ‘store’ method.
In most of the Linux distributions, the zip command also supports the ‘bzip2’ compression method.
How to create a password-protected zip file?
If you want to store your sensitive information in a zip archive, then use the option ‘-e’ for archive encryption as follows:
The above command will be asked you to enter and verify the password for the archive:
Create a split Zip file by specifying the size
Sometimes, you need to store data on another server or file hosting service that only allows you to upload limited file size. For example, you have 2 Mb of data for upload, but it allows you to upload only 100 kb data files. In this situation, you can create a split archive file using option ‘-s’ followed by the limited specified archive file size as follows:
After reaching the specified size limit, the above command creates a new zip archive file in the home directory.
Utilization of zip command
Using the zip command-line utility, you can create a zip archive containing all files of the current directory.
To create an archive file by including all hidden files as follows:
You can also create a zip archive of all MP3 files of the current directory without compressing files as follows:
The above command ‘-0’ shows the compression level. When you use compression level ‘0’, the file will be stored in the archive without any compression. The compressions level varies from ‘-0 to -9’. The ‘-6’ is the default compression level, and when you use ‘-9’ it will force the zip command to adopt the optimized compression for all files.
Method 2: Zip a folder using Gnome GUI
The following steps you need to perform while zipping a folder using Gnome graphical desktop environment:
Use the Gnome desktop, and navigate to the folder that you want to zip.
Select and right-click on the folder. Now, choose option ‘compress’ from the drop-down list as follows:
Next, choose the ‘.zip’ extension and assign a suitable name for the zip archive. Now, click on ‘Create’ as follows:
You will notice the zip archive will be created in the current directory where the original folder resides.
Conclusion
We discussed how to create a zip archive using the zip command-line utility in Ubuntu 20.04 system. We presented two methods for zipping a folder using the command line and using the Gnome GUI method. Based on your requirements, you can choose a suitable method. I hope the details mentioned above about zipping a folder using the zip command will help you.