CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Archiving & Compression / unzip

unzip

List, test and extract ZIP archives

Beginnerarchiveessentialcloud

unzip extracts .zip files, and can also list their contents, test them, or print a single member to stdout. You'll use it constantly for downloads such as the AWS CLI installer, Terraform binaries and Lambda packages.

Syntaxunzip [OPTIONS] ARCHIVE.zip [MEMBER...] [-x EXCLUDE...] [-d DIR]

Watch it run

On a fresh Ubuntu server you install AWS CLI v2, which is distributed as a zip with an installer inside.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
unzip awscliv2.zip

Minimal and cloud images often lack unzip. Ubuntu's command-not-found helper tells you the package.

Anatomy of a command

$
commandunzip

Info-ZIP's extractor for .zip archives (also .jar, .war, .apk).

How it works

unzip opens the archive and seeks to the end to find the end-of-central-directory record, then reads the central directory: the list of members with their sizes, CRCs and offsets. That's why unzip -l is instant on a huge file, and why a truncated download fails immediately with 'End-of-central-directory signature not found'. To extract, it seeks to each member's local header, inflates the data (DEFLATE, or copies stored data), verifies the CRC32, creates directories as needed, and restores Unix permission bits if the zip was made on Unix. Owners are not stored; files belong to whoever runs unzip. Member names can contain ../ or absolute paths (the 'zip slip' attack); unzip strips leading / and refuses ../ by default, but code that extracts zips itself must check.

Options you'll actually use

-lList contents: size, date, name
-vVerbose list: method, compressed size, ratio, CRC
-tTest the archive (CRC of every member)
-d DIRExtract into DIR
-o / -nAlways overwrite / never overwrite existing files
-qQuiet
-jJunk paths: extract every file into one directory
-pExtract a member to stdout (for pipes)
-x PATTERNExclude members
-P PASSPassword on the command line (visible in ps; avoid)
-Z / zipinfoDetailed listing with permissions, like ls -l

Common mistakes

unzip release.zip in your home directory without looking

If the zip has no top-level folder, dozens of files land directly in the current directory.

unzip -l release.zip first, or unzip release.zip -d release/
Plain unzip in a CI or deploy script

If files exist, unzip prompts, and with no terminal the job hangs or fails.

unzip -o (overwrite) or -n (never overwrite), plus -q
unzip -P 'secret' archive.zip on a shared server

The password is visible to every user in ps and lands in shell history.

Let unzip prompt for it
Writing your own extraction code that joins member names to a target path

Names like ../../etc/cron.d/x escape the target directory (zip slip).

Resolve each path and reject anything outside the target directory

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Make a zip of ~/app, then list its contents without extracting.

  2. 2

    Extract app.zip into /tmp/unzipped, overwriting anything already there, without per-file output.

  3. 3

    Print one file from app.zip to the terminal without extracting.

  4. 4

    Test the archive's integrity.

Related commands

zipCreate ZIP archives that open everywheretarBundle files into an archive and extract themcurlMake HTTP requests and debug APIs
PreviouszipNextapt
Linux / Archiving & Compression / unzip

unzip

List, test and extract ZIP archives

Beginnerarchiveessentialcloud

unzip extracts .zip files, and can also list their contents, test them, or print a single member to stdout. You'll use it constantly for downloads such as the AWS CLI installer, Terraform binaries and Lambda packages.

Syntaxunzip [OPTIONS] ARCHIVE.zip [MEMBER...] [-x EXCLUDE...] [-d DIR]

Watch it run

On a fresh Ubuntu server you install AWS CLI v2, which is distributed as a zip with an installer inside.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
unzip awscliv2.zip

Minimal and cloud images often lack unzip. Ubuntu's command-not-found helper tells you the package.

Anatomy of a command

$
commandunzip

Info-ZIP's extractor for .zip archives (also .jar, .war, .apk).

How it works

unzip opens the archive and seeks to the end to find the end-of-central-directory record, then reads the central directory: the list of members with their sizes, CRCs and offsets. That's why unzip -l is instant on a huge file, and why a truncated download fails immediately with 'End-of-central-directory signature not found'. To extract, it seeks to each member's local header, inflates the data (DEFLATE, or copies stored data), verifies the CRC32, creates directories as needed, and restores Unix permission bits if the zip was made on Unix. Owners are not stored; files belong to whoever runs unzip. Member names can contain ../ or absolute paths (the 'zip slip' attack); unzip strips leading / and refuses ../ by default, but code that extracts zips itself must check.

Options you'll actually use

-lList contents: size, date, name
-vVerbose list: method, compressed size, ratio, CRC
-tTest the archive (CRC of every member)
-d DIRExtract into DIR
-o / -nAlways overwrite / never overwrite existing files
-qQuiet
-jJunk paths: extract every file into one directory
-pExtract a member to stdout (for pipes)
-x PATTERNExclude members
-P PASSPassword on the command line (visible in ps; avoid)
-Z / zipinfoDetailed listing with permissions, like ls -l

Common mistakes

unzip release.zip in your home directory without looking

If the zip has no top-level folder, dozens of files land directly in the current directory.

unzip -l release.zip first, or unzip release.zip -d release/
Plain unzip in a CI or deploy script

If files exist, unzip prompts, and with no terminal the job hangs or fails.

unzip -o (overwrite) or -n (never overwrite), plus -q
unzip -P 'secret' archive.zip on a shared server

The password is visible to every user in ps and lands in shell history.

Let unzip prompt for it
Writing your own extraction code that joins member names to a target path

Names like ../../etc/cron.d/x escape the target directory (zip slip).

Resolve each path and reject anything outside the target directory

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Make a zip of ~/app, then list its contents without extracting.

  2. 2

    Extract app.zip into /tmp/unzipped, overwriting anything already there, without per-file output.

  3. 3

    Print one file from app.zip to the terminal without extracting.

  4. 4

    Test the archive's integrity.

Related commands

zipCreate ZIP archives that open everywheretarBundle files into an archive and extract themcurlMake HTTP requests and debug APIs
PreviouszipNextapt