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:

  1. Maximum compression (level 9 — smallest size, takes longer):

    zip -9 -r archive.zip /path/to/folder
    
  2. Zip the current directory:

    zip -9 -r archive.zip .
    
  3. Exclude files or folders (great for skipping logs, caches, etc.):

    zip -9 -r archive.zip /var/www --exclude="*.log" --exclude="cache/*"
    
  4. Password-protect the archive (note: encryption is basic — use only for light protection):

    zip -9 -r --password "StrongPass123" secure.zip important_files/
    
  5. Zip multiple folders/files at once:

    zip -9 -r archive.zip folder1 folder2 file.txt
    

Our products and services

Web HostingReliable hosting services for websites of any scale.
Order
VPSFlexible cloud infrastructure with full root access.
Order
Dedicated ServersBare metal servers for maximum performance.
Order

Extracting a ZIP archive

  1. Extract to current directory:

    unzip archive.zip
    
  2. Extract to a specific folder (creates it if missing):

    unzip archive.zip -d /path/to/destination
    
  3. Extract only specific files:

    unzip archive.zip important/file.txt
    
  4. 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 -r when zipping folders — otherwise subdirectories are skipped
  • Use -9 for maximum compression when size matters most (but it's slower)
  • Add -v for 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!

Need help?Our engineers will help you free of charge with any question in minutesContact us