Creating a zip in the Linux distribution system can be done in two ways: one is the graphical method, and the other one is the command-line-based method. In this how-to zip a folder in Linux guide, I will be guiding you through the different zip utilities and directory structure-based zipping and unzipping folders in Linux. Additionally, we will see the compression level-based zipping of the folder in the Linux distribution system.
In this Guide,
- Installing Zip on Debian-based Linux Distributions
- Creating a Zip File based on the Compression Level
- Creating a Zip file in the Working Directory
- How to Zip a Folder in Linux (Graphical method)
- Extracting the Zip File (Graphical method)
- Creating a Zip in the Working Directory (command line)
- Extracting a Zip File (Command-line)
- Frequently Asked Questions [FAQs]
- Wrapping up: How to Zip Folder in Linux
Installing Zip on Debian-based Linux Distributions
Before actually installing the zip utilities on Linux distributions, we first need to update the apt using the following command –
$ sudo apt-get update
The above command requires a lot of data, time, and space on your Linux distribution. You can skip this step if you are not facing any issues using the below command.
Now you can install the zip utilities using the following command –
$ sudo apt-get install zip unzip –y
Creating a Zip File based on the Compression Level
To use the zip utilities based on the compression level, you can use the compression range (1-10), with 1 being the fastest compression but less optimal file and 9 being slow compression but optimal file. But you might now have a question: What is the default compression when no level is specified? The answer is level 6 compression, which is the default compression for creating a zip in the Linux distributions.
The zip command used with a specific compression level is as follows –
$ zip -1 desktop.zip Desktop /* Fast compression & Less Optimal file */
In the above code, we specified level 1 as the compression level, which gives us faster compression and less optimal files. If you want a more optimal file, you can specify level 9(Max), but it will take a lot of time for compression.
You can change the compression level by replacing the number 1 with a different single-digit number in the range of 1-9.
Also read: Things to Do After Installing Kali Linux
Creating a Zip file in the Working Directory
There are two ways to zip a folder in Linux distributions:
- Graphical method
- Command-line method
Both methods can be used to create a zip file in the working directory. However, the graphical method is much simpler for zipping a directory structure and later extracting the zip file with one click. Moreover, if you have a good hand on the command line interface, you can readily go for it.
Also read: How to delete files and directories in Linux – Simple Guide
How to Zip a Folder in Linux (Graphical method)
To create a zip file directory structure using the graphical method, use the following steps –
- Go to the specific folder location on your Linux operating system.
- Right-click on the folder to be zipped.
- Select the compress option from the menu.
- Now you have to enter the name for the zipped file and select the “.zip” option.
- The zipped folder is now created in the same directory.
Extracting the Zip File (Graphical method)
Once you have created a zip file, you can use the following steps to extract the zip file –
- Right-click on the zipped file
- Select the Extract Here option from the menu
Use extract here if you want to unzip all the files in the same directory structure; if you want to extract all the files in a different directory, then select the “extract to” option and specify the path to the directory.
Also Read: How to Check the Version of Linux?
Creating a Zip in the Working Directory (command line)
The command-line options are equally easy to use but require familiarity with Linux commands and their use. If these commands are not properly used, you may end up deleting the zip folder from your Linux system.
The following are steps to zip a folder in Linux using the command line method –
- Open the directory where the folder is located.
- Right-click in the window and open the terminal. Type the following command
$ cd /home/alpha
- Here, Alpha is the folder to be zipped in the home directory.
- The following command is used to zip the folder where Alpha is the name of the final file, and output is the directory.
$ zip -r $HOME/Alpha.zip
- The zipped folder has been created and can be found using the ls command.
Also read: How to Rename Files and Directories in Linux?
Extracting a Zip File (Command-line)
To extract a zip file using the command-line interface, use the following steps –
Change the working directory to where the zip folder is available & type the following command –
$ cd Directory_path
Here, the Directory_path is the location where we will be extracting the zip file.
The following command is used to locate the zipped folder.
$ unzip Alpha.zip
Here, Alpha is the zipped folder.
Frequently Asked Questions [FAQs]
Most Linux distributions, especially Debian-based systems, do not come with zip utilities pre-installed. To use the zip and unzip commands, you need to install them with: $ sudo apt-get install zip unzip –y.
The default compression level in Linux is level 6. It provides a balance between compression speed and file optimization. You can customize this using compression levels between 1 (fastest, least optimal) and 9 (slowest, most optimal).
Yes, you can directly run the installation command without updating the package manager. However, updating ensures you have the latest package versions and avoids potential installation errors.
The graphical method is more user-friendly and requires minimal knowledge of Linux commands, making it ideal for beginners. The command-line method, however, offers more customization and flexibility for advanced users.
Misusing commands, especially in the command-line method, can lead to errors like file overwrites or unintended deletions. Always double-check the command and paths before executing.
Yes, you can specify particular files or folders to zip using their paths. For example: $ zip -r archive.zip /path/to/folder /path/to/file.
Yes, zip files created in Linux can be extracted on other operating systems like Windows and macOS, ensuring cross-platform compatibility.
Before You Leave
Get Our Prime Content Delivered to your Inbox for Free!! Join the Ever-Growing Community… Right Now.
Give this article a quick share,
Wrapping up: How to Zip Folder in Linux
To sum up, these are the best ways to create a zip file on a Linux distribution; you can use both the graphical and zip command methods to zip a folder in Linux. Likewise, extracting the zip file involves the same two methods. Additionally, You can use the compression level along with the zip utilities to have a much more optimal file in your working directory.
Did the guide work for you? Let us know in the comment section below. Also, share this guide with your friends on Reddit, Facebook, and other social communities to help us share a word. Join our Telegram Channel, Facebook Page, Reddit Community, and X to never miss our tech updates.