Skip to content

7z

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

7z is the native format of 7-Zip, Igor Pavlov’s open-source archiver. It uses LZMA2 (the algorithm behind xz) with large dictionaries, and by default compresses all files together as one solid block, so similar files share context. For collections of many similar files, it is typically the smallest common archive format, well ahead of ZIP. It also does AES-256 encryption (including file names) and applies filters that help executables and some binary data.

7-Zip is also a general archive reader: it opens ZIP, tar, gz, xz, bz2, RAR, ISO, WIM, disk images and many others, and since 24.01 it can unpack .zst files.

On Windows use the 7-Zip installer. On Linux, use your distribution’s 7zip package or the official 7zz build from 7-zip.org; the old p7zip is unmaintained. The command is 7z or 7zz.

Terminal window
7z a archive.7z dir/ # create (LZMA2, level 5)
7z a -mx=9 archive.7z dir/ # maximum compression
7z a -mx=9 -md=256m archive.7z dir/ # bigger dictionary
7z x archive.7z -oout/ # extract with paths into out/
7z l archive.7z # list
7z t archive.7z # test
7z a -p -mhe=on secret.7z dir/ # AES-256, encrypt file names too (prompts for password)

The options that matter:

SwitchEffect
-mx=0…9Level; default 5. 9 is “ultra”
-md=NmLZMA2 dictionary size; bigger finds more repeats but needs that much RAM to compress and extract
-ms=onSolid archive (default); -ms=off allows fast extraction of single files at a worse ratio
-mmt=NThread count; all cores by default
-mhe=onEncrypt file names as well as data (needs a password)
-t7z, -tzip, -txz, -tbzip2, -tgzipOutput format

Use -bso0 -bsp0 to silence output in scripts.

  • Solid archives are slow to extract from. Pulling one file out of a solid 7z means decoding everything before it in the same block. Use -ms=off or smaller solid blocks (-ms=100m) when you need random access.
  • Not for Unix backups. 7z does not preserve Unix owner/group, ACLs or extended attributes, so use tar with xz or zstd for system backups and preserve permissions.
  • No recovery data. A damaged 7z can often be partly extracted, but there is no built-in repair; keep a second copy or use PAR2.
  • Compatibility: not built into macOS or most Linux file managers without a 7-Zip/p7zip install. Choose ZIP for strangers.
  • Large dictionaries require the same memory on extraction; -md=1536m archives can fail on small devices.