Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · file management

zip

an archive everyone can open

zip creates the archive format every desktop system understands without extra software. Unlike tar it compresses each file separately and does not preserve Linux ownership, so it is for sharing rather than for backups.

tar.gz between Linux machines; zip when the other end is Windows or macOS.

Creates
.zip files
compressed per file
Directories
Need -r
or only the empty directory is stored
Order
Archive, then files
zip out.zip in...
Opens with
unzip
a separate package

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashzip
$ zip -r site.zip site/
1 adding: site/ (stored 0%)
2 adding: site/index.html (deflated 63%)
adding: site/css/ (stored 0%)
adding: site/css/style.css (deflated 71%)
3$ zip -e secret.zip passwords.txt
Enter password:
Verify password:
4 adding: passwords.txt (deflated 41%)
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
Directories are stored, not compressed

A directory has no contents of its own, so there is nothing to shrink: 0%.

2
deflated is the saving

index.html became 63% smaller. Text compresses well; photos and video, already compressed, barely change.

3
-e asks for a password

The password is not shown as it is typed. It is asked twice to catch a mistake.

4
The names are still visible

Encryption protects the contents only. Anyone can list the archive and see that it holds passwords.txt.

Switches

A switch changes how the command behaves. These are the ones used day to day; man zip lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-r
Recursive: include a directory and everything inside it.
-e
Encrypt: ask for a password.
-u
Update: add only files that are new or changed.
-d
Delete entries from an existing archive.
-x PATTERN
Exclude files matching the pattern.
-9
Best compression. -1 is fastest; -0 stores without compressing.
-q
Quiet: do not list each file.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

zip -r project.zip project -x "*.git*"

Leaves out everything matching a pattern.

zip -u site.zip site/index.html

Updates one file inside an existing archive.

zip -9 -r small.zip docs/

Uses the strongest compression, at the cost of time.

zip -d site.zip "site/old.html"

Deletes an entry from the archive.

In cybersecurity

The password option is weaker than it looks.

Classic zip encryption is broken

The default scheme used by -e can be cracked quickly. For anything sensitive use 7z with AES, or encrypt the file with gpg or age.

Do not put the password on the command line

-P password leaves it in your shell history and visible to other users in the process list. Use -e and type it.

Ownership is lost

A zip does not record Linux owners, and may not keep permissions. Restoring a system from one will not give back what you had.

Filed under

File management

Read alongside