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.
How to extract a zip archive in each shell
unzip archive.zipDefault behaviour: extract into current directory, prompt before overwriting. `-d /target` extracts to a different directory. `-o` overwrites without prompting. `-l` lists contents without extracting. `unzip -P pass archive.zip` for encrypted zips.
unzip archive.zipunzip archive.zipExpand-Archive archive.zip -DestinationPath .pwsh 5+ (Win10+/Windows PowerShell 5.1). `-Force` overwrites existing files. NO native support for encrypted zips — falls back to `7z x -p"$pass" archive.zip` if 7-Zip is installed, or `[System.IO.Compression.ZipFile]` doesn't accept passwords.
tar.exe -xf archive.zipWindows 10 1803+ ships BSD libarchive `tar.exe` which understands zip, tar, tar.gz, tar.xz, 7z, and more. No native `unzip` command before Win10 — pre-installs need `Expand-Archive` (pwsh) or third-party (7-Zip, WinRAR).
Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- **`unzip` is NOT installed by default on many minimal Linux distros** (Alpine, slim Docker images, RHEL UBI minimal). Quick check: `command -v unzip` returns nothing. Install: `apk add unzip` / `apt install unzip` / `dnf install unzip`. The universal-fallback that's ALWAYS present: `python3 -c "import zipfile; zipfile.ZipFile('archive.zip').extractall()"`. Or use `bsdtar -xf archive.zip` if available (BSD tar reads zip natively; macOS ships it as `tar`, Linux as `bsdtar` from `libarchive-tools`).
- **macOS has TWO `unzip` binaries with different behaviour**: `/usr/bin/unzip` (Info-ZIP, the classic one — same as Linux) and the macOS Archive Utility GUI which the Finder uses on double-click. The GUI auto-creates a subfolder if extracting multiple top-level entries (`unzip` does not). For "extract exactly what's inside" matching GUI behaviour: `ditto -x -k archive.zip target/` (macOS-native, handles resource forks correctly for old Mac apps). `unzip` mangles HFS+ resource-fork files (`._foo`) — use `ditto` for any archive that originated on a Mac.
- **Encrypted zips diverge by tool**: Info-ZIP `unzip -P pass archive.zip` works but the password appears in `ps` output — use `unzip archive.zip` (prompts) for security. `7z x -ppass archive.zip` (note `-p` immediately followed by password, no space). pwsh `Expand-Archive` does NOT support passwords at all — must use `Add-Type -AssemblyName System.IO.Compression.FileSystem` + `[System.IO.Compression.ZipFile]` which also doesn't support legacy ZipCrypto. **AES-encrypted zips** (the modern secure form): NEITHER native unzip nor pwsh Expand-Archive handle these — 7-Zip is the cross-platform answer. Anti-pattern: storing ZipCrypto-encrypted zips for security (cracked by free tools in seconds).
- **Path-traversal safety (zip slip)**: a malicious zip can contain entries like `../../etc/passwd` that escape the target directory and overwrite system files. Most modern `unzip` implementations DEFEND against this (refuse paths starting with `..`/`/`), but older ones don't. ALWAYS extract untrusted zips to a TEMP directory and inspect first: `mkdir /tmp/scratch && (cd /tmp/scratch && unzip /downloads/untrusted.zip) && ls /tmp/scratch/`. pwsh `Expand-Archive` has had patches for path-traversal CVEs (CVE-2018-8284 and later) — keep pwsh updated.
- **Zipbomb defence**: a 42 KB zip can extract to 4.5 PB (the classic `42.zip` bomb). Symptoms: extract appears to be making progress, but disk fills. Defence: `unzip -l archive.zip` first — sums "Uncompressed Size" column. If total > X×compressed size (say 1000×), treat as suspicious. `python3 -c "import zipfile; z=zipfile.ZipFile('a.zip'); print(sum(i.file_size for i in z.infolist()))"` returns total expanded size. Production: extract to a cgroup-limited container or a disk-quota-limited filesystem so runaway extraction is bounded.
Related commands
Related tasks
- Extract a tar archive— Unpack a `.tar`, `.tar.gz`, or `.tar.bz2` file into the current directory.
- Compress files into a zip archive— Bundle a folder or set of files into a single `.zip` archive.
- Extract a gzip file— Decompress a `.gz` file — single-file compression you encounter in `.tar.gz`, log rotation (`access.log.gz`), and package metadata.
- Extract a 7z archive— Unpack a `.7z` file — the highest-ratio common archive format, popular on Windows software downloads and big game/asset bundles.