How to Zip a Folder in Linux

28/12/2020
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 <Enter> 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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Thuê mua proxy Iphone uy tín, chất lượng cao

Thuê mua proxy Iphone cho phép bạn truy cập vào những nội dung bị hạn chế do khu vực địa lý hoặc...
10/05/2024

[NFS] [LAB] Hướng dẫn triển khai NFS

I) Mô hình II) IP Planning III) Triển Khai 1: Trên NFS Server Bước 1: Cài đặt yum install nfs-utils...
30/12/2020

Install XFCE on OpenSUSE

Among all the desktop environments out there, XFCE is truly a magnificent one. It’s visually appealing, intuitive and...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024