ZIP is a highly useful archive file format that helps in storage and file management. With an efficient zipping utility in tow, you can share multiple files and folders efficiently by combining them into one single file.

In Linux, zipping a folder saves a lot of space and network bandwidth. Since its development in 1989, ZIP has become one of the preferred ways to compress data and reduce the file size.

Using some native commands like zip, you too can zip a folder on Linux-based systems with ease.

How to Install zip on Linux

Most of the time, you won't find the zip utility installed on your Linux system by default. To install zip, you can use your distribution's default package manager.

On Ubuntu and Debian:

        sudo apt install zip
    

Install zip on CentOS and Fedora using:

        sudo yum install zip
    

On Arch Linux and Manjaro:

        sudo pacman -S zip
    

Run the following command to install zip on OpenSUSE:

        sudo zypper install zip
    

How Does the Zipping Process Work?

As soon as the zip command is invoked, the utility starts scanning the files specified in the input. In case the scan takes more than five seconds, the zip command will display the message: Scanning files.

The interesting part is, how you as a user, can understand what’s happening in the backend. If the output displays progress dots at an interval of every two seconds, it means the files are being processed.

If the time lapsed is more than two seconds, it means either the command is taking time to locate the files or the network connection is slow. In case zip is not able to locate a specific file, it will issue a warning, but still, continue to process your request.

Finally, in case some files are skipped during the process, the command will issue a warning at the end, telling you how many files it processed and how many it skipped.

Related: How to Zip and Unzip or Extract TAR and TAR.GZ Files

Zipping a Folder Using the Command Line

Use the following command syntax to zip folder(s):

        zip -r outputfile folder1 folder2 folder3
    

...where outputfile is the name of the archive and folder1, folder2, and folder3 are the absolute or relative path to the folders.

Let’s try to archive the data folder in a zip file named temp.zip. To do so, run this command:

        zip –r temp.zip /data
    

After running the aforementioned command, use the Is command to confirm the creation of the archive.

        ls –l | grep .zip
    

If the zip command determines the file size is too big, it will store the file as it is within the archive, without compressing it.

Specifying Compression Levels

You can specify the compression method using the -Z flag.

        zip -r -Z bzip2 archivename.zip directory_name
    

The output will show the compression levels of each file added to the archive.

Additionally, you can specify the compression levels by using numbers ranging from zero to nine. The default value is -6; however, use -0 to store files without compression. On the other hand, -9 will force the zip command to use an optimal compression for all the files within the archive.

        zip -9 -r archivename.zip directory_name
    

Zipping a Folder Using find

To zip a folder with an unknown path, you can use the find command effectively. Firstly pipe find to the exec command so that you can execute the zip command for the creation of an archive.

For zipping folders present in the current working directory, run this command:

        find . –maxdepth 1 type d –exec zip archive.zip {} +
    

Using this option is quite helpful as you get the flexibility for choosing archive folders recursively. You can also choose to have a certain level of folders zipped into your archive.

Using the GUI for Zipping Folders

Mostly every desktop environment within Linux includes a way to zip files. Even though this guide focuses on Ubuntu, rest assured, the procedure will be similar for other Linux distros as well.

To create a compressed (zipped) file using the graphical user interface, launch your system's file manager application from the Applications menu.

Once the window opens up, select the folders you would like to compress. To select multiple folders, keep the Ctrl key pressed while clicking on the folders.

Compress files using Linux GUI

Once done, right-click on any of the folders to open up a menu. Select the Compress button. The dialog box will ask you for the following:

  • Archive name
  • Type of Archive (options include ZIP, TAR.XZ, and 7Z)

Once you have entered the name and selected the type of zipped file, hit the Create button on top.

Create archive using GUI

Save Storage on Linux by Compressing Folders

The zip command is rather easy to use considering the complexity of other utilities in the Linux ecosystem. While the GUI process is seamless and quite straightforward, the alternate process of using the terminal is not that difficult either, especially if you can master the right commands to do the needful.