Sometimes, you want to share a directory or folder that contains a bundle of files with someone. In this situation, compressing the folder in a .zip file format is a good approach. Zip is the commonly used and popular archive file format in many operating systems for file compression that provides lossless data compression features.

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 update

$ sudo apt install zip

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-244.png" data-lazy- height="271" src="data:image/svg xml,” width=”912″>

After installing the zip utility, check the installed version by using the following command:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-245.png" data-lazy- height="135" src="data:image/svg xml,” width=”911″>

Zip a folder using the zip utility

To zip a folder through the command line, use the follow the following syntax:

$ zip options archive-name.zip folder-name

Example

For example, we want to zip a folder ‘MyDocsFolder’. The following command will create a zip archive of this folder:

$ zip -r MyDocsFolder.zip MyDocsFolder

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-246.png" data-lazy- height="205" src="data:image/svg xml,” width=”911″>

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 archivefolder.zip MyFolder1 MyFolder2 file1.txt file2.txt


$ zip -r MyDocsFolder.zip MyDocsFolder PersonalFolder file1.txt file2.txt file3.txt

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-247.png" data-lazy- height="351" src="data:image/svg xml,” width=”905″>

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:

$ zip -e  archivename.zip directory_name

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-248.png" data-lazy- height="120" src="data:image/svg xml,” width=”911″>

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:

$ zip -s 100k -r archivename.zip directory_name

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-249.png" data-lazy- height="155" src="data:image/svg xml,” width=”911″>

After reaching the specified size limit, the above command creates a new zip archive file in the home directory.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-250.png" data-lazy- height="657" src="data:image/svg xml,” width=”900″>

Utilization of zip command

Using the zip command-line utility, you can create a zip archive containing all files of the current directory.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-251.png" data-lazy- height="347" src="data:image/svg xml,” width=”910″>

To create an archive file by including all hidden files as follows:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-252.png" data-lazy- height="666" src="data:image/svg xml,” width=”911″>

You can also create a zip archive of all MP3 files of the current directory without compressing files as follows:

$ zip -0 archivename *.mp3

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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-253.png" data-lazy- height="745" src="data:image/svg xml,” width=”1001″>

Select and right-click on the folder. Now, choose option ‘compress’ from the drop-down list as follows:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-254.png" data-lazy- height="711" src="data:image/svg xml,” width=”915″>

Next, choose the ‘.zip’ extension and assign a suitable name for the zip archive. Now, click on ‘Create’ as follows:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-255.png" data-lazy- height="703" src="data:image/svg xml,” width=”914″>

You will notice the zip archive will be created in the current directory where the original folder resides.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-256.png" data-lazy- height="720" src="data:image/svg xml,” width=”924″>

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.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/49ac9cf0c583f1d7e06205a87f549d76?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Samreena Aslam

Samreena Aslam holds a master’s degree in Software Engineering. Currently, she’s working as a Freelancer & Technical writer. She’s a Linux enthusiast and has written various articles on Computer programming, different Linux flavors including Ubuntu, Debian, CentOS, and Mint.