Skip to content
Latchkey

unzip -o: Overwrite Without Prompting

unzip -o overwrites existing files silently; unzip -n skips any file that already exists.

The default unzip behavior is to ask before overwriting, which has no answer in a non-interactive job and stalls it. -o and -n make the choice up front.

What it does

When a file to be extracted already exists, plain unzip prompts "replace <file>? [y]es, [n]o, [A]ll, [N]one, [r]ename". unzip -o overwrites without prompting; unzip -n never overwrites and keeps the existing file. -o is the usual choice for a clean extraction into a fresh or stale directory.

Common usage

Terminal
# overwrite existing files, no prompt
unzip -o artifact.zip -d ./out
# never overwrite, keep what is there
unzip -n artifact.zip -d ./out

Options

FlagWhat it does
-oOverwrite existing files without prompting
-nNever overwrite, skip existing files
-d <dir>Extract into the named directory
-qQuiet, suppress the listing

In CI

Always pass -o (or -n) when extracting into a directory that might already contain files; otherwise the interactive replace prompt has no input and the job hangs until it times out. This is one of the most common silent CI stalls. Even a single pre-existing file triggers the prompt.

Common errors in CI

A job that hangs at the extract step with no further output is almost always unzip waiting on the "replace?" prompt; add -o. If files unexpectedly remain old after extraction, -n is set somewhere and is skipping them. Feeding y to stdin works but -o is cleaner and explicit.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →