Comprimare

How to Zip a Folder in Linux

How to Zip a Folder in Linux
In this article, I will show you how to Zip and Unzip a Folder or Directory in Linux.  This might seem trivial, but sometimes people will struggle to get it right. Let's get started.

Installing Zip Utilities on Ubuntu/Debian

First update the apt package repository cache with the following command:

$ sudo apt-get update

The apt package repository cache should be updated.

Now install zip and unzip packages with the following command:

$ sudo apt-get install zip unzip -y

Zip and unzip packages should be installed. In my case, they are already installed.

Installing Zip Utilities on RHEL 7/CentOS 7

First update the yum package repository cache with the following command:

$ sudo yum makecache

Now install the zip and unzip packages with the following command:

$ sudo yum install zip unzip

Now press y and then press to continue.

zip and unzip packages should be installed.

Zipping a Folder/Directory Graphically

If you have any graphical desktop environment installed on your chosen Linux distribution, then you can use it to Zip archive any folder you like very easily.

First open your favorite File Manager and go to the location where you have the folder you want to Zip archive. In my case I am using the Nautilus file manager in GNOME 3 desktop environment.

Let's say you want to Zip archive the Downloads/ directory as marked in the screenshot below.

Now right click on the Downloads/ directory and click on Compress… as marked in the screenshot below.

Now type in a name for your Zip archive and select .zip

Once you're done, click on Create.

A backup.zip file should be created. This is the Zip archive of the Downloads/ directory.

Zipping a Folder/Directory using the Command Line Interface (CLI)

If you don't have any graphical desktop environment installed on your computer, don't worry. You can still use the command line interface (CLI) to Zip archive a folder.

First go to the location where the folder you want to zip archive is available with the following command:

$ cd PATH

NOTE: PATH is the location where your desired folder is located.

For example, if you want to Zip archive the /etc directory. So the PATH should be the root directory /.

Again, if you want to Zip archive the /etc/apt directory, then the PATH should be /etc.

Let's Zip archive, /etc/apt directory.

$ cd /etc

The command for Zipping a folder or directory is:

$ zip -r OUTPUT.zip FOLDER

NOTE: Here FOLDER is the directory that you want to Zip archive. OUTPUT is the path to a file where the Zip archive of FOLDER will be saved.

For example, run the following command to Zip archive /etc/apt directory and save it to the HOME directory of your login user as apt_backup.zip:

$ zip -r ~/apt_backup.zip apt/
Or
$ zip -r $HOME/apt_backup.zip apt/

The /etc/apt directory or folder should be Zip archived.

It should be save to ~/apt_backup.zip file as you can see from the screenshot below.

$ ls -lh ~
Or
$ ls -lh $HOME

Extracting the Zip Archive Graphically

If you have a graphical desktop environment installed, then extracting the Zip archive is very easy.

Just right click on the Zip archive you want to extract and you should see the following menu. Select either Extract Here or Extract to… to unzip it.

If you want to extract the archive to your current working directory (the directory you're in right now), then click on Extract Here. It should be extracted as you can see from the marked section of the screenshot below.

If you want to extract it to a different directory, then click on Extract to…

A directory picker should be opened as you can see in the marked section of the screenshot below.

Select a directory and click on Select.

The Zip archive should be extracted in that directory as you can see in the marked section of the screenshot below.

Extracting the Zip Archive using the Command Line Interface (CLI)

If you don't have the graphical desktop environment installed on your Linux distribution, don't worry. You can extract the Zip archive using the command line interface (CLI).

First navigate to the directory where you want to extract the Zip archive with the following command:

$ cd EXTRACT_DIR

NOTE: EXTRACT_DIR is the directory where you want to extract the Zip archive.

Then run the following command to extract the Zip archive:

$ unzip ZIP_ARCHIVE.zip

NOTE: Here ZIP_ARCHIVE is the path to the Zip archive that you want to extract.

For example, let's extract the ~/apt_backup.zip file to ~/Downloads/ directory.

First navigate to the ~/Downloads directory:

$ cd ~/Downloads

Now run the following command to extract apt_backup.zip file:

$ unzip ~/apt_backup.zip

~/apt_backup.zip file should be extracted.

The extracted apt/ directory.

That's how you Zip and Unzip a Folder or Directory in Linux. Thanks for reading this article.

Battle for Wesnoth Tutorial
The Battle for Wesnoth is one of the most popular open source strategy games that you can play at this time. Not only has this game been in developmen...
0 A.D. Tutorial
Out of the many strategy games out there, 0 A.D. manages to stand out as a comprehensive title and a very deep, tactical game despite being open sourc...
Unity3D Tutorial
Introduction to Unity 3D Unity 3D is a powerful game development engine. It is cross platform that is it allows you to create games for mobile, web, d...