unzip Command

The unzip command in Linux is used to extract files from a .zip archive. It is a powerful utility that can handle various aspects of ZIP archives, including listing their contents, testing their integrity, and extracting files to specified locations.

Syntax

unzip [OPTION]... FILE[.zip] [FILE(S) ...] [-x FILE(S) ...] [-d EXDIR]

Description

unzip lists, tests, or extracts files from a ZIP archive, commonly found on MS-DOS systems. The default behavior (with no options) is to extract all files from the specified ZIP archive into the current directory.

Common uses include:

  • Extracting all files from a ZIP archive
  • Extracting specific files from a ZIP archive
  • Listing the contents of a ZIP archive without extracting
  • Extracting files to a different directory

Common Options

Option Description
-l List archive files (short format)
-v List archive files (verbose format)
-t Test archive files for integrity
-d EXDIR Extract files into EXDIR (e.g., -d /tmp/extract_here)
-x FILE(S) Exclude the specified files from extraction
-o Overwrite existing files without prompting
-q Perform operations quietly (suppress most output)

Examples

Extract a zip file to the current directory

unzip myarchive.zip

Extracts all files from 'myarchive.zip' into the current directory.

Extract a zip file to a specific directory

unzip myarchive.zip -d /tmp/extracted_files

Extracts all files from 'myarchive.zip' into the '/tmp/extracted_files' directory.

List contents of a zip file

unzip -l myarchive.zip

Lists the contents of 'myarchive.zip' without extracting them.

Extract specific files from a zip archive

unzip myarchive.zip file1.txt folder/file2.jpg

Extracts only 'file1.txt' and 'folder/file2.jpg' from 'myarchive.zip'.

Extract all files except specified ones

unzip myarchive.zip -x unwanted.txt

Extracts all files from 'myarchive.zip' except 'unwanted.txt'.

See also