Log inSign up

Work with zip files on a Linux server

Install the tools with sudo apt install zip unzip or sudo dnf install zip unzip. Then zip -r site.zip public/ packs a folder, unzip -l site.zip lists it and unzip site.zip -d /srv/site extracts into a chosen directory. Use zip when the archive will be opened on Windows or macOS; between Linux servers, tar keeps more metadata.

Topic: File transfer and archives · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

When does zip make more sense than tar?

Pick zip when a person on Windows or macOS will open the file, or when a web application, plugin installer or upload form expects a .zip. Every desktop system can open zip files without extra software, and individual files inside can be read without unpacking the rest.

The trade-off is metadata: zip keeps names, folders and timestamps, and basic Unix permissions, but not owners, ACLs or SELinux labels. For moving data between Linux servers or making system copies, the tar archives guide is the better fit.

How do I install zip and unzip?

The two commands come in separate packages, and minimal server images often have neither.

# Ubuntu 24.04 / 22.04, Debian 12 / 13
sudo apt update
sudo apt install zip unzip

# Rocky Linux 9, AlmaLinux 9
sudo dnf install zip unzip

zip -v | head -n 2
unzip -v | head -n 1

Both are small, unchanged for years and safe to keep installed on any server, from the smallest plan up.

How do I create a zip archive?

Give the archive name first and the files or folders after it; -r is required for directories, otherwise zip only stores the empty folder entry.

zip report.zip report.pdf summary.csv
zip -r site.zip public/
zip -rq -9 logs.zip /var/log/nginx
cd /var/www && zip -r ~/example-net.zip example.net

-q hides the per-file output, and -9 asks for maximum compression (the default level 6 is usually close enough). The last line changes directory first so paths inside the archive start at example.net/ rather than var/www/. Symlinks are followed by default; add -y to store them as links instead.

How do I exclude files or update an existing zip?

-x takes one or more patterns that must be quoted so the shell does not expand them first.

zip -r app.zip app/ -x "app/node_modules/*" "app/.git/*" "*.log"

# add new and changed files to an existing archive
zip -ru app.zip app/

# make the archive match the folder, removing deleted files from it
zip -r -FS app.zip app/

-u updates entries that are newer on disk, and -FS (file sync) also drops entries for files that no longer exist. That makes a zip handy as a rolling copy of a small folder.

How do I list, test and extract a zip file?

Look inside before you unpack, then always say where the files should go.

unzip -l site.zip
unzip -t site.zip
unzip site.zip -d /srv/site
unzip site.zip "public/css/*" -d /tmp/css-only
unzip -j site.zip "*.pdf" -d ~/pdfs

-t checks every entry against its stored CRC, so it catches incomplete downloads. -j drops the folder structure and puts matching files flat in one place. When an extracted file already exists, unzip asks what to do; answer once for all with -o (overwrite) or -n (never overwrite) for scripts. Archives created on Windows sometimes contain backslashes in paths or no execute bits on scripts; fix modes afterwards with chmod, as explained in file permissions.

How do I protect a zip with a password properly?

Use AES-256 through 7-Zip, not the classic zip password. zip -e applies the old ZipCrypto scheme, which can be broken with freely available tools, so treat it as a privacy screen at most.

# Ubuntu 24.04, Debian 12 and 13
sudo apt install 7zip
# Rocky Linux 9, AlmaLinux 9 (EPEL)
sudo dnf install epel-release
sudo dnf install p7zip

7z a -tzip -mem=AES256 -p secrets.zip secrets/
7z x secrets.zip -o/tmp/secrets

The -p flag without a value makes 7z prompt for the password instead of saving it in your shell history. AES encrypted zip files open in 7-Zip, macOS Archive Utility alternatives and most modern archive tools. Send the password through a different channel than the file.

How do I split a big archive into parts?

zip can write a split archive with a fixed part size, which helps when an upload form or mail gateway has a size limit.

zip -r -s 500m dataset.zip dataset/
ls dataset.z*

# rejoin into one file before extracting
zip -s 0 dataset.zip --out dataset-full.zip
unzip dataset-full.zip -d /srv/data

The parts are named dataset.z01, dataset.z02 and a final dataset.zip; all of them must be present.

How do I move a zip to or from the server?

Build the archive on the server, then download it with scp or sftp:

ssh deploy@198.51.100.24 "cd /var/www && zip -rq /tmp/site.zip example.net"
scp deploy@198.51.100.24:/tmp/site.zip .
ssh deploy@198.51.100.24 rm /tmp/site.zip

Do not leave archives in a public web folder for downloading: anything under the document root can be fetched by anyone who guesses the name. Remove temporary archives once the transfer is done so they do not fill the disk.

Which zip and unzip errors are common?

  • End-of-central-directory signature not found: the file is truncated or not a zip at all. Download it again and run file name.zip.
  • zip warning: name not matched: the path does not exist or the pattern was expanded by the shell; quote patterns.
  • skipping: need PK compat. v5.1: the archive uses AES or another newer method; extract it with 7z x.
  • Garbled file names from archives made on older Windows systems: on Ubuntu and Debian, try unzip -O cp437 file.zip.

Questions about zip and unzip

Does zip keep Linux permissions?

It stores basic mode bits, and unzip on Linux restores them. It does not keep owners, groups, ACLs or extended attributes; use tar for that.

Can I read a file inside a zip without extracting everything?

Yes: unzip -p site.zip public/robots.txt prints one entry to the terminal, and zipgrep pattern site.zip searches inside all entries.

Is zip compression as good as zstd or xz?

Usually not. zip compresses each file separately with deflate. For big backups between servers, a .tar.zst is smaller and faster to create.

How do I unzip a .gz or .tar.gz file?

Those are not zip files. Use gunzip file.gz or tar -xzf file.tar.gz instead.

Is there a size limit?

Current zip and unzip support Zip64, so archives and files above 4 GB work, though some older desktop tools may struggle with them.