unzipList, test and extract ZIP archives
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.
unzip [OPTIONS] ARCHIVE.zip [MEMBER...] [-x EXCLUDE...] [-d DIR]On a fresh Ubuntu server you install AWS CLI v2, which is distributed as a zip with an installer inside.
unzipInfo-ZIP's extractor for .zip archives (also .jar, .war, .apk).
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.
-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 -lunzip release.zip in your home directory without lookingIf 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 scriptIf files exist, unzip prompts, and with no terminal the job hangs or fails.
unzip -o (overwrite) or -n (never overwrite), plus -qunzip -P 'secret' archive.zip on a shared serverThe password is visible to every user in ps and lands in shell history.
Let unzip prompt for itWriting your own extraction code that joins member names to a target pathNames like ../../etc/cron.d/x escape the target directory (zip slip).
Resolve each path and reject anything outside the target directoryTry these on a Linux machine of your own. Each task has a hint and a solution.
Make a zip of ~/app, then list its contents without extracting.
Extract app.zip into /tmp/unzipped, overwriting anything already there, without per-file output.
Print one file from app.zip to the terminal without extracting.
Test the archive's integrity.
unzipList, test and extract ZIP archives
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.
unzip [OPTIONS] ARCHIVE.zip [MEMBER...] [-x EXCLUDE...] [-d DIR]On a fresh Ubuntu server you install AWS CLI v2, which is distributed as a zip with an installer inside.
unzipInfo-ZIP's extractor for .zip archives (also .jar, .war, .apk).
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.
-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 -lunzip release.zip in your home directory without lookingIf 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 scriptIf files exist, unzip prompts, and with no terminal the job hangs or fails.
unzip -o (overwrite) or -n (never overwrite), plus -qunzip -P 'secret' archive.zip on a shared serverThe password is visible to every user in ps and lands in shell history.
Let unzip prompt for itWriting your own extraction code that joins member names to a target pathNames like ../../etc/cron.d/x escape the target directory (zip slip).
Resolve each path and reject anything outside the target directoryTry these on a Linux machine of your own. Each task has a hint and a solution.
Make a zip of ~/app, then list its contents without extracting.
Extract app.zip into /tmp/unzipped, overwriting anything already there, without per-file output.
Print one file from app.zip to the terminal without extracting.
Test the archive's integrity.