Skip to content
shellmap

7z7-Zip archive create/extract, LZMA2 compression, AES-256 encryption, 7zz modern fork vs p7zip unmaintained across all 5 shells

Equivalents in every shell

Bashunix
7z x archive.7z

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

Zshunix
7z x archive.7z
Fishunix
7z x archive.7z
PowerShellwindows
Expand-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.

cmd.exewindows
7z x archive.7z

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

Bash
7z x archive.7z
Fish
7z x archive.7z
PowerShell
Expand-7Zip -ArchiveFileName archive.7z -TargetPath .
cmd.exe
7z x archive.7z

Create archive with strong compression + AES-256 encryption + encrypted file list

Bash
7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir/
Fish
7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir/
PowerShell
Compress-7Zip -Path dir -ArchiveFileName archive.7z -Password "PASSWORD" -EncryptFilenames -CompressionLevel Ultra
cmd.exe
7z a -p"PASSWORD" -mhe=on -mx=9 archive.7z dir\

List archive contents (no extraction)

Bash
7z l archive.7z
Fish
7z l archive.7z
PowerShell
Get-7ZipInformation -ArchiveFileName archive.7z
cmd.exe
7z l archive.7z

Gotchas

  • **`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

pwshpwsh cross-platform: `Install-Module 7Zip4PowerShell` provides `Compress-7Zip` / `Expand-7Zip` / `Get-7ZipInformation` cmdlets that wrap the native `7z` binary. Cross-platform behaviour is consistent — same archive works on Linux/macOS/Windows.
WSLWSL: `7zz` (modern) or `p7zip` (legacy) work on WSL filesystem. For accessing Windows-side `7z.exe`: `cmd.exe /c "7z.exe x C:\archive.7z"` via interop. Mixed pipeline: extracting a Windows-encrypted archive on Linux needs the SAME 7z binary version that encrypted it — 7-Zip 21.07+ supports `-mhe=on` archives from any platform; older p7zip 16.x cannot decrypt header-encrypted archives created by 21.07+ in some edge cases.

Common tasks using 7z

Related commands