Working with ZIP archives in Linux
A practical guide to creating, extracting, and managing ZIP files in Linux.
ZIP is one of the most universal archive formats — natively supported on Windows, macOS, Linux, and virtually every device. It compresses files and folders efficiently and is perfect for quick sharing or backups when compatibility matters most.
Important note: ZIP's built-in encryption (especially older versions) is weak by modern standards. For sensitive data, use stronger alternatives like tar + xz or 7z instead.
Installing ZIP and unzip
Ubuntu / Debian:
sudo apt update
sudo apt install zip unzip -y
CentOS / Rocky / AlmaLinux:
sudo yum install zip unzip -y
or (newer versions):
sudo dnf install zip unzip -y
Creating a ZIP archive
Basic command to zip a folder recursively:
zip -r archive.zip folder/
Useful variations:
-
Maximum compression (level 9 — smallest size, takes longer):
zip -9 -r archive.zip /path/to/folder -
Zip the current directory:
zip -9 -r archive.zip . -
Exclude files or folders (great for skipping logs, caches, etc.):
zip -9 -r archive.zip /var/www --exclude="*.log" --exclude="cache/*" -
Password-protect the archive (note: encryption is basic — use only for light protection):
zip -9 -r --password "StrongPass123" secure.zip important_files/ -
Zip multiple folders/files at once:
zip -9 -r archive.zip folder1 folder2 file.txt
Our products and services
Extracting a ZIP archive
-
Extract to current directory:
unzip archive.zip -
Extract to a specific folder (creates it if missing):
unzip archive.zip -d /path/to/destination -
Extract only specific files:
unzip archive.zip important/file.txt -
Extract password-protected archive:
unzip -P "StrongPass123" archive.zip
Viewing archive contents (without extracting)
List files inside:
unzip -l archive.zip
This shows filenames, sizes, dates, and compression ratios — very useful for checking what's inside before extracting.
Handy tips & best practices
- Always include
-rwhen zipping folders — otherwise subdirectories are skipped - Use
-9for maximum compression when size matters most (but it's slower) - Add
-vfor verbose output — see exactly what's being processed - ZIP struggles with very large files (>4 GB) or deeply nested paths — switch to tar.xz in those cases
- Verify archive integrity after creation:
unzip -t archive.zip
Recommendation
ZIP is great for cross-platform sharing and Windows compatibility, but for server backups, long-term storage, or sensitive data, tar.xz is superior — it compresses better, handles large files flawlessly, and offers stronger integrity. See our detailed guide: Working with tar archives
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!