
How to Install and Use Zip and Unzip on Linux: A Complete Guide
The .zip
format is a universal standard for compressing and archiving files. Whether you’re downloading software, sharing project files, or backing up data, you will inevitably encounter zip archives. While most desktop Linux distributions come with graphical tools to handle these files, the core command-line utilities—zip and unzip—are not always installed by default, especially on servers.
This guide will walk you through the simple process of installing these essential tools on your Linux system and cover the basic commands to get you started with creating and extracting zip files right from the terminal.
Verifying if Zip and Unzip are Already Installed
Before proceeding, it’s wise to check if the utilities are already on your system. You can do this by checking their version. Open your terminal and type the following commands:
zip --version
unzip -v
If these commands return version information, you’re all set and can skip to the usage section. If you see an error like “command not found,” you’ll need to install them using the instructions below.
How to Install Zip and Unzip on Linux
The installation process is straightforward but depends on the package manager used by your Linux distribution. We’ve covered the most popular families of Linux operating systems below.
For Debian, Ubuntu, and Mint
For distributions based on Debian, such as Ubuntu, Linux Mint, and Pop!_OS, you’ll use the apt
package manager.
- First, it’s always a good practice to update your package repository list to ensure you get the latest versions available.
bash
sudo apt update
- Next, install both the
zip
andunzip
packages with a single command.
bash
sudo apt install zip unzip
For CentOS, RHEL, and Fedora
For Red Hat-based systems like RHEL (Red Hat Enterprise Linux), CentOS, and Fedora, you will use either dnf
or yum
. dnf
is the modern standard, while older systems (like CentOS 7) still use yum
.
- To install using the
dnf
package manager (Fedora, RHEL 8+, CentOS 8+):
bash
sudo dnf install zip unzip
- For older systems using the
yum
package manager (CentOS 7, RHEL 7):
bash
sudo yum install zip unzip
For Arch Linux
For Arch Linux and its derivatives like Manjaro, you will use the pacman
package manager.
- First, synchronize the package databases.
bash
sudo pacman -Syu
- Then, install the required packages.
bash
sudo pacman -S zip unzip
Basic Usage: How to Create and Extract Zip Files
Once installed, managing zip files from the command line is incredibly efficient. Here are the most common commands you’ll need.
Creating a Zip Archive
To compress files into a new zip archive, use the zip
command followed by the desired archive name and the files you want to include.
To compress one or more individual files:
zip my_archive.zip file1.txt document.pdf image.jpg
This command creates
my_archive.zip
containing the three specified files.To compress an entire directory and its contents:
You must use the-r
(recursive) flag to include all files and subdirectories within a folder.
bash
zip -r my_project_backup.zip /path/to/my_project/
This creates a complete backup of themy_project
directory.
Extracting a Zip Archive
To decompress a zip file, use the unzip
command.
To extract files into the current directory:
This is the simplest use case. It will unpack all contents of the archive into the folder you are currently in.unzip my_archive.zip
To extract files into a specific directory:
It’s often cleaner to extract files into a designated folder. Use the-d
flag to specify a destination directory.unzip my_archive.zip -d /path/to/destination_folder/
If the destination folder doesn’t exist,
unzip
will attempt to create it for you.To list the contents of a zip file without extracting:
If you want to see what’s inside an archive before you unpack it, use the-l
flag.
bash
unzip -l my_archive.zip
Important Security Tip
While zip files are generally safe, always be cautious when extracting archives from untrusted sources. A malicious zip file can contain malware or attempt to overwrite important system files.
As a security best practice, always list the contents of an unknown archive with unzip -l
before extracting it. Furthermore, it’s wise to extract archives from unknown sources into a dedicated, isolated directory rather than a critical system path like your home directory. After extraction, check the file permissions to ensure no executable flags have been set without your knowledge.
By mastering these simple commands, you are now fully equipped to handle zip archives efficiently and securely on any Linux system.
Source: https://www.tecmint.com/install-zip-and-unzip-in-linux/