# 7z

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

7z is the native format of [7-Zip](https://7-zip.org/), Igor Pavlov's open-source archiver. It uses LZMA2 (the algorithm behind [xz](/codecs/data/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](/codecs/data/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.

## Install

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

## Common commands

```sh
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:

| Switch                                       | Effect                                                                                           |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `-mx=0…9`                                    | Level; default 5. 9 is "ultra"                                                                   |
| `-md=Nm`                                     | LZMA2 dictionary size; bigger finds more repeats but needs that much RAM to compress and extract |
| `-ms=on`                                     | Solid archive (default); `-ms=off` allows fast extraction of single files at a worse ratio       |
| `-mmt=N`                                     | Thread count; all cores by default                                                               |
| `-mhe=on`                                    | Encrypt file names as well as data (needs a password)                                            |
| `-t7z`, `-tzip`, `-txz`, `-tbzip2`, `-tgzip` | Output format                                                                                    |

Use `-bso0 -bsp0` to silence output in scripts.

## Pitfalls

- **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](/codecs/data/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.
