Skip to content
Log In Sign Up info@muvcloud.com

The zip Commands You Will Use Most

zip notes.zip notes.txt todo.txt
zip -r site.zip site
zip -r site.zip site -x 'site/cache/*'
unzip -l site.zip

The archive name comes first, then the files to add. -r adds a folder with everything inside it, -x leaves out paths that match a pattern, and unzip -l lists the result. If the archive already exists, zip adds the files to it instead of starting a new one.

Install zip

sudo apt install zip
sudo dnf install zip

The first line is for Ubuntu and Debian, the second for AlmaLinux and Rocky Linux. zip and unzip are separate packages, and minimal server images often include neither. If the shell reports that zip is not found, installing the package is the fix; command not found covers the general case.

Zip a Folder

cd /var/www
zip -r ~/example-site.zip example.com

Without -r, zip adds only the folder entry and none of its files. zip stores paths as you type them, so run it from the parent folder: the archive then holds example.com/ and not var/www/example.com/. Hidden files such as .htaccess are included when you name the folder itself, but not when you write example.com/*; see how to show hidden files. zip follows symbolic links and stores the files they point to; add -y to store the links themselves.

Leave Files Out

zip -r site.zip site -x 'site/node_modules/*' '*.log'

Patterns after -x are compared with the paths as they are stored in the archive, and * also matches across slashes. Quote each pattern so the shell does not expand it first. Check the result with unzip -l site.zip.

Add, Update, and Remove Entries

CommandWhat it does
zip site.zip new.htmlAdds or replaces a file
zip -ru site.zip siteAdds only new or changed files
zip -d site.zip 'site/old.html'Removes an entry
zip -T site.zipTests the archive

-m moves files into the archive and deletes the originals afterward. Avoid it unless you have another copy.

Compression Levels

zip -9 -r logs.zip logs
zip -0 -r photos.zip photos

Levels run from -0 (store only, no compression) to -9 (smallest and slowest); the default is -6. Text, SQL dumps, and logs shrink a lot. Images, videos, and files that are already compressed barely shrink, so -0 saves time for them.

Password Protection Is Weak

zip -e -r private.zip private

-e asks for a password twice and encrypts the files with the classic ZIP method. That method is old and weak: known attacks can recover the contents, so treat it as protection against casual opening only. Never pass the password with -P on the command line, because it ends up in your shell history and is visible in the process list. For data that must stay private, encrypt the archive with gpg: gpg -c private.zip asks for a passphrase and writes private.zip.gpg. To move it to another server, use scp, which encrypts the transfer.

zip vs tar.gz

Pointziptar.gz
Owners and groupsNot restored by defaultRestored as root
Symbolic linksFollowed by defaultKept as links
One file outFastReads the archive
Other computersOpens almost anywhereMay need a tool

For server backups and moving sites between Linux servers, tar.gz is the better fit because it keeps permissions, owners, and links; see how to extract tar.gz files. zip suits files you send to people who open them on their own computers. To extract a zip archive on the server, see how to unzip files in Ubuntu.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations