Linux unzip Command: List and Extract ZIP Archives

unzip checks the list of files in a ZIP archive and extracts files. By checking the member names and destination before extracting, you can reduce overwriting existing files or creating unexpected paths.

What is the unzip command?

By default, it extracts to the current directory. You can specify the target directory with -d, check the list with -l, and test for archive data errors with -t. -n skips existing files, and -o overwrites without asking, so you need to be especially careful.

Basic syntax

unzip [Options] Archive.zip [-d target directory]

The installed implementation and options may vary depending on the distribution. Check the description for your system with man unzip.

Examples

Check archive file list

Check the paths and number of files before extracting.

unzip -l project.zip

Extract to an empty target directory

Extract separately to avoid mixing with other files.

mkdir -p restore
unzip project.zip -d restore/

Skip existing files

Use -n when you want to keep files with the same name.

unzip -n project.zip -d restore/

Check the paths and list before extracting

unzip -Z -1 shows only the file names inside the ZIP line by line without extracting. For unfamiliar ZIPs, check the list and paths first.

unzip -Z -1 bundle.zip

Example output:

docs/readme.txt
images/logo.png

For actual extraction, it is safer to specify a separate directory like unzip bundle.zip -d target-directory. Make sure that the names inside the archive do not conflict with unexpected paths or existing files, and do not execute files immediately after extracting files from unfamiliar sources. unzip -t helps to check the archive structure.

Main Options and Format

Options/Format Description
-l List the names, sizes, etc., of files in the ZIP.
-t Check the compressed data without extracting files.
-d directory Specify the destination directory for extraction.
-n Do not overwrite existing files.
-o Overwrite existing files without confirmation.

Precautions when using

Do not extract ZIP files from untrusted sources with administrator privileges; first, check the contents in an isolated directory. Verify the paths inside the archive, symbolic links, and disk space, and avoid automatic overwriting with -o. The archive check -t does not guarantee the safety of the file contents.

Frequently Asked Questions

How to extract a ZIP without touching existing files?

The clearest way is to specify a separate empty directory. If you need to extract to an existing directory, skip files with the same name using -n.

Official Documentation

You can check the exact behavior of options and implementation differences in the official unzip documentation.

More in This Category
Linux Tutorial / Read Files with cat, less, more, head, and tail

Linux Tutorial / Read Files with cat, less, more, head, and tail

Learn when to use cat, less, more, head, and tail to read Linux files, with a small reproducible example and guidance for long files and logs.

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux hostnamectl Command: Show and Change the Host Name

Linux hostnamectl Command: Show and Change the Host Name

Learn how to show and Change the Host Name with the Linux hostnamectl command, including practical examples, key options, and important precautions.

Linux stat Command: Display Detailed File Metadata

Linux stat Command: Display Detailed File Metadata

Learn how to use the Linux stat command to inspect file size, permissions, ownership, timestamps, inode, and filesystem metadata, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux locate Command: Search Indexed File Paths Quickly

Linux locate Command: Search Indexed File Paths Quickly

Learn how Linux locate searches a filename database, how updatedb affects freshness, how to limit and filter matches, and when find is the better tool.

Linux mount Command: Inspect and Mount Filesystems

Linux mount Command: Inspect and Mount Filesystems

Learn how to inspect and Mount Filesystems with the Linux mount command, including practical examples, key options, and important precautions.

Linux cmp Command: Compare Files Byte by Byte

Linux cmp Command: Compare Files Byte by Byte

Learn how Linux cmp compares two files byte by byte, reports the first mismatch, runs silently in scripts, limits ranges, and differs from diff and checksums.

Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux more Command: View Text One Screen at a Time

Linux more Command: View Text One Screen at a Time

Learn how to use Linux more to read text one screen at a time, move and search interactively, start at a line or pattern, and choose between more and less.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.