unzip
Archives
Usage
unzip [-d <dir>] <archive.zip>Extracts a .zip, and without `-d` it empties straight into the current directory, so run `-l` first to see whether the archive has a top-level folder; names from older Windows zips need `-O CP932`, and a password given with `-P` is visible in your shell history and in ps.
Common flags
| Flag | Meaning |
|---|---|
| -l | List the contents without extracting. |
| -d <dir> | Extract there instead of into the current directory. |
| -o | Overwrite existing files without asking. |
| -n | Never overwrite: skip files that already exist. |
| -j | Flatten the paths into one directory. |
| -q | Quiet, for scripts. |
| -O CP932 | Interpret file names in a legacy code page (Debian/Ubuntu Info-ZIP only; stock macOS unzip rejects -O). |
| -P <password> | Password on the command line, where ps and your shell history can see it. |
Examples
unzip -l archive.zipCheck whether it has a top-level folder before extracting.
unzip archive.zip -d /tmp/outExtract somewhere harmless.
unzip -O CP932 japanese.zipFixes mojibake from an older Windows zip, where the patched Info-ZIP is available.
Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does unzip do?
Extracts a .zip, and without `-d` it empties straight into the current directory, so run `-l` first to see whether the archive has a top-level folder; names from older Windows zips need `-O CP932`, and a password given with `-P` is visible in your shell history and in ps.
Q. How do I type it?
unzip [-d <dir>] <archive.zip> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
8 are listed here; the full set is in man unzip. This command sits under Archives.
Related commands
man page: man unzip