How to compress a folder in Linux


ZIP is a very useful archive file format that makes it easy to store and manage files. With an efficient compression utility, you can efficiently share multiple files and folders by combining them into one file.

In Linux, compressing 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 file size.

Using native commands like Zip *: French, you can also easily compress a folder on Linux systems.

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 the default package manager for your distribution.

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 zipper process work?

As soon as the zip command is invoked, the utility starts scanning the files specified in the entry. If the scan takes more than five seconds, the zip command will display the message: File scanning.

The interesting part is how you as the user can figure out what is going on in the backend. If the output shows progress dots every two seconds, the files are being processed.

If the elapsed time is more than two seconds, it means that the command is taking a long time to locate the files or that the network connection is slow. If zip is unable to locate a specific file, it issues a warning, but continues to process your request nonetheless.

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

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

Compress a folder using the command line

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

zip -r outputfile folder1 folder2 folder3

…or output file is the name of the archive and folder1, folder2, and folder3 are the absolute or relative path of the folders.

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

zip –r /data

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

ls –l | grep .zip

If the zip command determines that the file size is too large, it will store the file as it is in the archive, without compressing it.

Specifying compression levels

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

zip -r -Z bzip2 directory_name

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

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

zip -9 -r directory_name

Compress a folder using find

To compress a folder with an unknown path, you can effectively use the find command. First pipe find to the the executive command so that you can run the Zip *: French command for creating an archive.

To compress the folders present in the current working directory, run this command:

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

Using this option is very useful as you have the ability to choose archive folders recursively. You can also choose to have a certain level of compressed folders in your archive.

Using the GUI to Compress Folders

Almost all Linux desktop environments include a way to compress files. Even though this guide focuses on Ubuntu, rest assured, the procedure will be similar for other Linux distributions 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, select the folders you want to compress. To select multiple folders, keep the Ctrl pressed while clicking on the folders.

Compress files using Linux GUI

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

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

Once you have entered the name and selected the compressed file type, press the button. To create button on the top.

Create an archive using the GUI

Save storage on Linux by compressing folders

The zip command is rather easy to use given the complexity of other utilities in the Linux ecosystem. While the GUI process is seamless and fairly straightforward, the alternate process of using the terminal isn’t that difficult either, especially if you can master the right commands to get the job done.

how to unzip zip files in linux

How to unzip ZIP files in Linux

Need help extracting a ZIP archive in Linux? Here’s how you can unzip a ZIP file, both graphically and using the command line.

Read more

About the Author


About Author

Leave A Reply