Saturday, September 24, 2022
Google search engine
HomeTechnologyHow to ZIP a Folder under Linux

How to ZIP a Folder under Linux

Folder compression can be a great way of organizing data and saving space. This is how to add folders into a Linux zip archive.

Photo by Mikel Parera on Unsplash

ZIP is an archive format that can be used to store and manage files. You can easily share multiple files or folders with an efficient zipping utility by tow. They can be combined into one file.

Zipping a folder in Linux can help you save a lot of space as well as bandwidth. ZIP was created in 1989 and has been a popular way to compress files and reduce file sizes.

You can zip files on Linux-based systems using native commands such as zip.

How to install zip on Linux

You won’t usually find the zip utility on your Linux system as a default. You can use the default package manager of your distribution to install zip.

Ubuntu and Debian:

sudo apt install zip

Use Fedora and CentOS to install zip

sudo yum install zip

Manjaro and Arch Linux:

sudo pacman -S zip

To install zip on OpenSUSE, run the following command:

sudo zip

How does the Zipping Process work?

Once the zip command has been invoked, the utility will start scanning the files specified by the input. If the scan takes longer than five seconds, the zip command will display this message: Scanning files.

What’s interesting is how you, as a user can understand what’s going on in the backend. The output should display progress dots every two seconds to indicate that files are being processed.

If it takes more than 2 seconds to complete the task, either the command is taking too long to locate the files or your network connection is slow. Zip will warn you if it is unable to locate a file. However, the process will continue.

Finaly, if files are lost during the process, the command will warn you at the end. It will tell you how many files were processed and which ones it skipped.

RELATED: Extracting TAR and TAR.GZ Files

Use the Command Line to Zip a Folder

To zip folders, use the following syntax:

zip-r outputfile folder1 and folder2

…where outfile is a name for the archive, folder1 and folder2 are the relative or absolute paths to the folders.

Let’s now try to archive the folder into a zip file called temp.zip. This command will do the trick:

zip.r temp.zip./data

To confirm the creation and deletion of the archive, run the above command.

 

grep .zip

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

Specification of compression levels

The or -Z flag can be used to specify the compression method.

zip -r -Z bzip2 archivename.zip directory_name

The output will display the compression levels for each file that was added to the archive.

You can also specify compression levels using numbers from zero to nine. The default value for is 6 . However, -0 can be used to store files with no compression. -9, on the other hand will cause the zip command use the best compression for all files in the archive.

zip -9 -r archivename.zip directory_name

 

Use find to zip a folder

The find command can be used to zip a folder that has an unknown path. First, pipe search to exec so you can run the zip commands for creating an archive.

This command can be used to zip folders in the current directory.

Find. -maxdepth 1 type d -exec zip archive.zip {} +

This option can be very useful as it allows you to choose archive folders recursively. You can also opt to have certain folders included in your archive.

Use the GUI to Zipping Folders

Most Linux desktop environments include a way of zipping files. This guide is focused on Ubuntu but the process will work for all Linux distros.

 

Launch the file manager application of your system from the Applications menu to create a compressed file (zipped).

Select the folders that you wish to compress once the window has opened. You can select multiple folders by pressing the Ctrlkey while clicking on them.

Right-click any folder to open a menu. Select the Compressbutton. You will be asked to enter the following information in the dialog box:

  • Archive Name
  • Types of Archive (options: ZIP, TAR.XZ and 7Z).

After you’ve entered your name and chosen the type of zip file, click the Create link at the top.

Linux Storage Savings by Compressing Folders

Considering the complexity of the Linux ecosystem, zip is quite simple to use. The GUI process is quite seamless and straightforward. However, it is possible to use the terminal alternatively if you know the commands.

 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments