Home·Terminal commands

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

FlagMeaning
-lList the contents without extracting.
-d <dir>Extract there instead of into the current directory.
-oOverwrite existing files without asking.
-nNever overwrite: skip files that already exist.
-jFlatten the paths into one directory.
-qQuiet, for scripts.
-O CP932Interpret 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.zip

Check whether it has a top-level folder before extracting.

unzip archive.zip -d /tmp/out

Extract somewhere harmless.

unzip -O CP932 japanese.zip

Fixes 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