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
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
Extracts all files from 'myarchive.zip' into the current directory.
Extract a zip file to a specific directory
Extracts all files from 'myarchive.zip' into the '/tmp/extracted_files' directory.
List contents of a zip file
Lists the contents of 'myarchive.zip' without extracting them.
Extract specific files from a zip archive
Extracts only 'file1.txt' and 'folder/file2.jpg' from 'myarchive.zip'.
Extract all files except specified ones
Extracts all files from 'myarchive.zip' except 'unwanted.txt'.