zip Package and compress files into a zip archive
Puts files and folders into a single .zip archive and compresses them. Zip files open on almost every system, including Windows, so it is a good choice for sharing. Use unzip to open one.
Synopsis
zip [OPTION]... archive.zip file ...
zip -r archive.zip folder ...
Common options
| Option or form | What it does |
|---|---|
-r | Include folders and everything inside them. Without it, zip adds only the folder entry and none of its contents |
-q | Quiet: do not print each file as it is added |
-j | Junk the folder names: store files by name only, without their path |
-x pattern | Exclude files that match the pattern. Put it after the file list and quote it |
-e | Encrypt the contents, asking for a password. This protection is weak |
-u | Update: add files that are new or changed since they were zipped |
-d | Delete the named entries from an existing zip file |
-0 to -9 | Compression level. -0 stores files uncompressed, -1 is fastest, -9 is smallest. The default is 6 |
Examples
zip -q notes.zip notes.txt app.log && unzip -l notes.zip | tail -1
zip -rq docs.zip docs && ls docs.zip
docs.zip
zip -rq site.zip docs photos -x '*.jpg' && unzip -l site.zip
zip -qj flat.zip docs/readme.md docs/old/report.txt && unzip -l flat.zip
zip -q notes.zip notes.txt && zip -q notes.zip data.csv && unzip -l notes.zip
zip -er private.zip docs
Notes
- Forgetting -r is the most common mistake. zip docs.zip docs stores an empty folder entry, not the files inside. Always use -r for a folder.
- If the zip file already exists, zip adds to it or replaces matching entries. It does not start a fresh file. Delete the old zip first if you want a clean archive.
- The password from -e only keeps casual readers out. The man page itself calls this the weak standard zip encryption. For anything sensitive, use a dedicated encryption tool. Do not put the password on the command line.
- Quote patterns given to -x, such as '*.jpg', so zip and not the shell matches them. Paths in the pattern are relative to what you named on the command line.
- Zip keeps per-file compression, so one damaged file rarely ruins the rest, but it usually compresses less than tar with gzip.
See also
Last reviewed 2026-10-07.