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.
Before going into the details, ensure that the zip command-line utility is installed on your system to zip a folder.
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:
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.
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 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.
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:
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.
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.
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.
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.
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…
Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…