11.07.2025

How to use zip on Linux?

The zip utility is a simple and convenient way to compress files or directories in the format.zip directly from the Linux command line. It is often used to back up, send data, and merge files.

In this article, you will learn:

Zip and unzip installation

If the utility is not installed, install it using the command depending on your system.:

# Ubuntu / Debian
sudo apt update
sudo apt install zip unzip

# CentOS / RHEL
sudo yum install zip unzip

# Arch Linux
sudo pacman -S zip unzip

Creating an archive

Archiving a single file:

zip archive.zip myfile.txt

Folder archiving recursively:

zip -r archive.zip myfolder/

Archiving multiple files and folders:

zip -r backup.zip folder1/ file2.txt notes.doc

Unpacking the archive

unzip archive.zip

Unpacking to the specified directory:

unzip archive.zip -d /path/to/folder/

Unpacking a single file:

unzip archive.zip file.txt

Additional options

Key Purpose
-r Recursively adding directories
-e Password encryption of the archive
-9 Maximum compression level
-x Exclusion of files by mask
-q Quiet mode

Creating a secure archive

zip -re secure.zip secret-folder/

After launching, you will be prompted to enter and confirm your password.

Working with files in an archive

Add a file to the archive:

zip archive.zip newfile.txt

To delete a file from the archive:

zip -d archive.zip oldfile.txt

Common errors

Error The reason The solution
command not found: zip The utility is not installed Install the zip through the package manager
filename not matched File not found Check the name and path
bad password Incorrect password Check the password or recreate the archive

Useful tips

The zip and unzip utilities are a reliable tool for compressing files on Linux. They are easy to use, do not require a GUI, and are ideal for automating archiving via scripts or cron.