7z — 7-Zip archive create/extract, LZMA2 compression, AES-256 encryption, 7zz modern fork vs p7zip unmaintained across all 5 shells
Equivalents in every shell
7z x archive.7zOn modern Linux (Arch, Fedora 38+, Debian 13+), `7z` is provided by `7-Zip` upstream as `7zz` — install via `pacman -S 7zip`, `dnf install 7zip`, `apt install 7zip`. Older systems still ship `p7zip` (`7z` binary) — UNMAINTAINED since 2016, missing modern format support (Zstandard, Brotli). Use `7zz` when available. `x` extract (preserves paths), `e` extract (FLATTENS — drops directory structure — #1 confusion source), `a` add (create or update), `l` list, `t` test integrity. `-y` answers yes to all prompts (for unattended scripts).
7z x archive.7z7z x archive.7zExpand-7Zip -ArchiveFileName archive.7z -TargetPath .Requires `Install-Module -Name 7Zip4PowerShell -Scope CurrentUser`. The pwsh-native `Expand-Archive` handles ZIP only — NOT 7z. Alternative: call the `7z.exe` binary directly: `& "$env:ProgramFiles\7-Zip\7z.exe" x archive.7z`. Cross-platform pwsh 7: `7-zip` from `dotnet tool install --global PowerShell.7Zip` works on Linux/macOS via the same `7-Zip4PowerShell` cmdlet.
7z x archive.7zAfter `winget install 7zip.7zip` (`C:\Program Files\7-Zip\7z.exe` — add to PATH). Or `choco install 7zip`. For cmd-native compression without 7-Zip: `tar -a -c -f archive.zip dir\` uses bsdtar (shipped Windows 10 1809+) to make a ZIP — but no .7z support.
Worked examples
Extract archive preserving directory structure
7z x archive.7z7z x archive.7zExpand-7Zip -ArchiveFileName archive.7z -TargetPath .7z x archive.7zCreate archive with strong compression + AES-256 encryption + encrypted file list
7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir/7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir/Compress-7Zip -Path dir -ArchiveFileName archive.7z -Password "PASSWORD" -EncryptFilenames -CompressionLevel Ultra7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir\List archive contents (no extraction)
7z l archive.7z7z l archive.7zGet-7ZipInformation -ArchiveFileName archive.7z7z l archive.7zGotchas
- **`7z x` vs `7z e` is the #1 confusion source** — `x` preserves paths (recreates the directory structure inside the archive); `e` FLATTENS everything to the current directory, IGNORING subdirs, and overwrites if there are filename collisions. ALWAYS use `x` unless you specifically want flattening (rare — usually a single-file extract from a known location inside the archive). Forget this and a tarball containing `src/main.c` + `src/utils.c` + `tests/test.c` all land in one directory with `src/` and `tests/` lost. Silent data hazard.
- **`p7zip` (the binary "7z" on older Linux) is UNMAINTAINED since 2016** — last commit 2016, missing Zstandard (added to 7-Zip 21.07 in 2021), Brotli, modern AES improvements, and several CVE fixes. Modern alternative: `7zz` (Igor Pavlov's 7-Zip ported to Linux/macOS in 2021+, built from current upstream). Distros transitioning: Arch + Fedora 38+ + Debian 13+ already ship `7zz`; older Ubuntu LTS still has p7zip — `brew install sevenzip` provides `7zz` on macOS. For NEW scripts: prefer `7zz` over `7z` name to ensure modern binary.
- Encryption has TWO modes — content-only (default, `-p"pass"`) and header-too (`-p"pass" -mhe=on`). Without `-mhe=on`, the FILE LIST is readable without the password — `7z l encrypted.7z` shows every filename + size + mtime, just not contents. With `-mhe=on`, even `7z l` requires the password (the file LIST is also encrypted). For high-value archives where filenames leak information ("my-tax-returns-2025.pdf"), ALWAYS use `-mhe=on`. AES-256 with 2^19 SHA-256 password-stretching is the algorithm — practically uncrackable IF password is strong.
- **Solid mode (`-ms=on`, the default) is great for compression but BAD for partial extracts**. Solid mode treats all files as ONE giant block — produces 2-4x smaller archives than tar.gz on repetitive content (lots of similar source files, many small text files). The cost: extracting a SINGLE file requires decompressing UP TO that file from the start of the solid block. For archives that will be queried for individual files (catalogs, lookup tables), use `-ms=off` (non-solid — random-access, each file standalone). For one-shot backups extracted in full: solid mode wins.
- Path separators on Windows vs Linux — 7z stores paths with FORWARD slashes regardless of source OS (the archive format is platform-agnostic). But cmd users may expect `dir\file` and the archive lists `dir/file` — works either way on extract (7z normalizes). What DOES break: line-ending preservation. 7z does NOT auto-convert CRLF / LF — files extracted on Windows from a Linux-created archive keep their LF endings. Scripts that assume CRLF after Windows extract need `unix2dos` post-processing. Same trap as ZIP / tar.
WSL & PowerShell Core notes
Common tasks using 7z
- Extract a 7z archive
Unpack a `.7z` file — the highest-ratio common archive format, popular on Windows software downloads and big game/asset bundles.
- Extract a zip archive
Unpack a `.zip` file from the command line — the most common archive format on the web, and a frequent source of "how do I unzip on Windows without GUI" searches.
- List the contents of a tar archive
Show what's inside a `.tar`, `.tar.gz`, `.tar.xz`, etc. without extracting — for sanity-checking before unpacking, for grep-searching member names, and for size auditing.