zip Command Guide for Cross-Platform Archives
zip creates the .zip archive format that every desktop operating system can open natively — the format you reach for whenever a file has to travel to Windows or macOS.
What is zip, and Why Use It?
zip bundles files into a single .zip container with built-in compression, and unzip opens them back up. Unlike tar, which is Linux-native, .zip is understood by Windows Explorer, macOS Finder, and file managers everywhere — it is the lingua franca of “here is a folder, open it”. The trade-off: .zip does not preserve Linux file permissions and ownership the way tar does, so it is best for sharing documents and media, not for system backups.
Why Learn zip?
- Universally readable — no extra software needed on the receiving machine.
- The format you will get asked for — “send me a zip” is a common request.
- Password protection and splitting — built-in options
tarlacks. unzip -llists contents — inspect before extracting, same astar -t.
zipis about sharing, not backing up. If the archive needs to preserve permissions or live on a Linux server, usetar; if a human on another OS needs to open it, usezip.
1. Create a Zip Archive
To compress a single file:
zip documents.zip report.pdf
To bundle a whole directory, add -r (recursive):
zip -r project.zip myproject/
-r walks the directory tree and stores every file, keeping the folder structure inside the archive. Without -r, zip complains that myproject/ is a directory.
Check the result:
ls -lh project.zip
2. Add Files to an Existing Archive
You can keep appending to a zip:
zip project.zip notes.md
zip -u project.zip src/main.c
-u— update: only replace files that are newer than what is already in the archive.
3. Extract an Archive
unzip project.zip
This unpacks into the current directory. To choose a destination:
unzip project.zip -d ~/restored/
-d— the destination directory (created if missing).
Unzipping into a fresh directory is the safe habit — running unzip in a directory full of same-named files invites overwrites.
4. List Contents Without Extracting
unzip -l project.zip
-l— list the table of contents.
Output shows sizes, dates, and paths:
Archive: project.zip
Length Date Time Name
--------- ---------- ----- ----
0 2026-12-05 10:00 myproject/
1024 2026-12-05 10:00 myproject/README.md
--------- -------
1024 2 files
To extract just one file from the archive:
unzip project.zip myproject/README.md
5. Control What Gets Included
Exclude paths with -x:
zip -r project.zip myproject/ -x "*.git*" -x "node_modules/*"
Compress more aggressively with a level flag:
zip -r -9 project.zip myproject/
-1through-9— compression level;-9is smallest,-1is fastest. The default is-6.
6. Password-Protect an Archive
zip -er secret.zip sensitive/
-e— encrypt (prompt for a password).
You will be asked twice. Extraction requires the same prompt:
unzip secret.zip
7. Test and Repair
Check a suspect download:
unzip -t project.zip
-t— test the integrity of the archive.
To overwrite existing files during extraction without being asked:
unzip -o project.zip
-o— overwrite without prompting.
Common Pitfalls
- Forgetting
-ron directories —zip archive.zip myfolder/alone refuses to work; add-rto include the tree. - Expecting permission preservation — zip does not reliably store Linux permissions and ownership; use
tarfor backups. - Extracting over existing files — plain
unzipasks before overwriting;-oskips the questions but can clobber work. Extract into a fresh directory when unsure. - Assuming zip works everywhere the same — some archives created on Windows with odd filenames extract with mangled names on Linux; prefer ASCII filenames when sharing.
- Using zip for huge files —
.ziphas a 4 GB per-file limit in the classic format; for very large data usetarwithxzor split archives.
Related Pages
| Page | Relationship |
|---|---|
| tar | The Linux-native archive format; preserves permissions |
| gzip | The single-file compressor inside .tar.gz and .zip |
| xz | Higher-ratio compression for .tar.xz |
| bzip2 | Older compressor used by some .zip implementations |
zip Cheatsheet
| Command | What it does |
|---|---|
zip file.zip doc.pdf | Zip a single file |
zip -r archive.zip dir/ | Recursively zip a directory |
zip -u archive.zip file | Update only newer files in the archive |
unzip archive.zip | Extract into the current directory |
unzip archive.zip -d /path/ | Extract into a specific directory |
unzip -l archive.zip | List contents without extracting |
unzip archive.zip path/inside | Extract one file |
zip -r -9 archive.zip dir/ | Zip with maximum compression |
zip -er secret.zip dir/ | Create a password-protected archive |
unzip -t archive.zip | Test archive integrity |
unzip -o archive.zip | Extract, overwriting without prompting |