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:
- How to install zip and unzip
- How to archive and decompress files
- How to encrypt an archive
- Typical mistakes and tips
Zip and unzip installation
If the utility is not installed, install it using the command depending on your system.:
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:
Folder archiving recursively:
Archiving multiple files and folders:
Unpacking the archive
Unpacking to the specified directory:
Unpacking a single file:
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
After launching, you will be prompted to enter and confirm your password.
Working with files in an archive
Add a file to the archive:
To delete a file from the archive:
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
- Avoid spaces in paths, or use quotation marks:
zip "archive name.zip" "My Folder/"
- Add the date to the archives:
zip -r backup_$(date +%Y-%m-%d).zip data/
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.