# ZIP

Canonical URL: https://encode.wiki/codecs/data/zip/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): c5e214ac78213f167063e617bac6aca28cbaf40539f4ab275f98410d41b9871b

ZIP is an archive format: one file holding many entries, each compressed on its own and listed in a central directory at the end. That makes extracting a single file fast and appending cheap, and every operating system opens `.zip` natively. The price is a weaker ratio than [7z](/codecs/data/7z/) or `.tar.xz`, because entries are compressed independently (no shared dictionary across files). Use ZIP when the recipient might be anyone; also remember that `.docx`, `.jar`, `.apk`, `.epub` and `.cbz` are ZIP files.

## Common commands

```sh
zip -r archive.zip dir/              # Deflate, recurse
zip -r -9 archive.zip dir/ -x '*.tmp'   # best Deflate, exclude pattern
zip -r -y archive.zip dir/           # store symlinks as links
unzip -l archive.zip                 # list
unzip -t archive.zip                 # test
unzip archive.zip -d out/            # extract into out/
```

Running `zip` on an existing archive adds and replaces entries (`-u` only updates changed ones); `-0` stores without compression, which is the right choice for already-compressed content such as video or JPEGs. The Info-ZIP `zip`/`unzip` tools are on most Linux systems; macOS and Windows ship their own, and `7z a -tzip` also works.

## Compression methods

The default is Deflate (method 8), and that is the only one you can count on everywhere. The format also defines others, which built-in OS tools and Info-ZIP `unzip` often cannot read:

| Method         | Notes                                                                 |
| -------------- | --------------------------------------------------------------------- |
| Deflate        | Universal; the default                                                |
| Deflate64      | Larger window variant; 7-Zip writes it, Info-ZIP `unzip` 6.0 reads it |
| bzip2          | `zip -Z bzip2` or 7-Zip; `unzip` 6.0 reads it                         |
| LZMA, xz, PPMd | 7-Zip and similar tools only; `unzip` 6.0 skips these entries         |
| Zstandard (93) | Added in APPNOTE 6.3.8; 7-Zip 24.01+ can read it                      |

For anything but Deflate, check that the other side's tool supports it. If you want better compression, use 7z or `.tar.zst` instead.

## Encryption and limits

- **Classic ZipCrypto** (`zip -e`) is weak and can be broken with known plaintext. AES-256 ZIP (`7z a -tzip -mem=AES256 -p`) is secure but unreadable to Info-ZIP `unzip` and to some built-in OS tools. File names stay readable either way.
- **ZIP64** removes the old 4 GiB and 65,535-entry limits; current tools write it automatically when needed. Very old extractors may not read it.
- **Metadata:** ZIP stores modification time and basic permissions but not Unix owner/group or xattrs. For system backups use [tar](/codecs/data/tar/).
- **File names:** non-ASCII names are the usual cross-platform problem. Modern tools write UTF-8 names with the correct flag; older ones use the local code page and show mojibake.
