How to Zip the Folder in Linux?

How to Zip the Folder in Linux?

The process of compressing folders or files is a useful feature in any operating system. When you have multiple files or folders to send as attachments through the internet, you would typically need to upload them one by one to any platform, taking great care not to forget any file or folder. To ensure the receiver gets their folders in a sequential format, we need to convert all the attachments into a compressed format to save time and internet resources. When you convert any file or folder to a zip format, their actual size is compressed. If you are a Linux user, this tutorial will provide information on how to zip a folder in the Linux operating system.

There are two simple and easy ways available to compress any folder to a zip format in the Linux operating system: creating a zip file with Terminal and GUI Desktop. Here are the ways to try on the Linux system.

Zip the Folder with Terminal

If you are currently using a Linux server as a storage server or web hosting server, you need to use this method to compress any folder to a zip format and save it on your server without using any more space. Before doing so, we need to install this on our server. From the given list, install the zip on your server.

For Debian/Ubuntu System:

$ sudo apt install zip

For Fedora/Redhat System:

$ Sudo dnf install zip

For Arch System:

$ Sudo pacman install zip

After installing this service, your Linux server is ready to zip any folder or file. There are multiple factors available for zipping a folder or file, like zipping the folder directly, zipping multiple folders into a single file, and zipping a folder with encryption. Now we can check each one.

Zip the Folder

To zip the folder directly over the terminal, first open the terminal at the folder directory and input the given command:

$ zip -r {Destination} {source}
inet70@inet70pvtltd:~/Desktop$ ls
folder
inet70@inet70pvtltd:~/Desktop$ zip -r fold folder
  adding: folder/ (stored 0%)
  adding: folder/inet70 Forum.png (deflated 12%)
  adding: folder/logo.png (deflated 3%)
inet70@inet70pvtltd:~/Desktop$ ls
fold.zip  folder
inet70@inet70pvtltd:~/Desktop$ 

In this command, you can input the name of the created zip file at the destination and give the folder name at the source location. For example, if I have one folder available for compression, I can input the given command example on the table to successfully compress it.

Zip Multiple Folders into a Single File

In some cases, we have multiple folders available to store or share with anyone. If we share the folders one by one, it consumes more internet and time. The file receiver might get confused about folder sequencing. In such cases, we can make a file from multiple folders:

$ zip -r {destination} {source1} {source2}
inet70@inet70pvtltd:~/Desktop$ ls
folder-1  folder-2
inet70@inet70pvtltd:~/Desktop$ zip -r merge-folder folder-1 folder-2
  adding: folder-1/ (stored 0%)
  adding: folder-1/inet70 Forum.png (deflated 12%)
  adding: folder-1/logo.png (deflated 3%)
  adding: folder-2/ (stored 0%)
  adding: folder-2/inet70 Forum.png (deflated 12%)
  adding: folder-2/logo.png (deflated 3%)
inet70@inet70pvtltd:~/Desktop$ ls
folder-1  folder-2  merge-folder.zip
inet70@inet70pvtltd:~/Desktop$ 

From the given example, you can see I have two folders, folder-1 and folder-2, available. If I need to compress both folders and convert them into a single zip file, I can follow the given command and successfully compress the objects into a folder.zip file. In my case, I just used two folders, but you can input any number of folders and compress them.

Compress Folder to Zip File with Encryption

In some cases, a shared file is accessible to everyone, and you need to share this file with a particular user. In this type of case, you can set up file access permissions to securely share the file. To share the file with a password, you can input the given formula:

$ zip -r -e {destination} {source}
inet70@inet70pvtltd:~/Desktop$ ls
folder
inet70@inet70pvtltd:~/Desktop$ zip -r -e private-folder folder
Enter password: 
Verify password: 
  adding: folder/ (stored 0%)
  adding: folder/inet70 Forum.png (deflated 12%)
  adding: folder/logo.png (deflated 3%)
inet70@inet70pvtltd:~/Desktop$ ls
folder  private-folder.zip
inet70@inet70pvtltd:~/Desktop$ unzip private-folder.zip
Archive:  private-folder.zip
[private-folder.zip] folder/inet70 Forum.png password: 

From the given script and data, I can see I have one folder available, and I can try to compress this folder with encryption. The zip compressor will ask me to set up the password. I can create and verify this password. When I try to access or unzip the following file, it will ask me for the password. This is the most secure option for private files.

Zip the Folder with GUI

If you are a GUI (Graphical User Interface) user, you can easily compress the folder into a zip format. This works for Gnome, KDE Plasma, and more desktop environments with different names but similar meanings. As a Gnome Ubuntu Desktop user, I can show you on my Gnome Desktop.

zip the folder with GUI

First, select the folder and right-click on this folder to show the "Compress to" option. Click on this option and select the zip option. Additionally, you can set up the password for this file by clicking on the optional button, set the password, and compress it.