Skip to content

ZIP

currentMigrated from docs/data/zip.mdx at 37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0

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 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.

Terminal window
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.

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:

MethodNotes
DeflateUniversal; the default
Deflate64Larger window variant; 7-Zip writes it, Info-ZIP unzip 6.0 reads it
bzip2zip -Z bzip2 or 7-Zip; unzip 6.0 reads it
LZMA, xz, PPMd7-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.

  • 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.
  • 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.