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 resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.

Linux Directory Structure Explained: Purpose of Major Directories

Linux Directory Structure Explained: Purpose of Major Directories

Understand the purpose of major Linux directories such as /etc, /var, /usr, /home, /proc, and /sys, and learn where common system files belong.

Linux screen Command: Create and Manage Detachable Terminal Sessions

Linux screen Command: Create and Manage Detachable Terminal Sessions

Learn how to use the Linux screen command to keep terminal sessions running and reconnect to them later, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux lscpu Command: Inspect CPU Architecture and Cores

Linux lscpu Command: Inspect CPU Architecture and Cores

Learn how to inspect CPU Architecture and Cores with the Linux lscpu command, including practical examples, key options, and important precautions.

Linux Tutorial / What Is Linux? Understanding the Kernel, Distributions, and Open Source

Linux Tutorial / What Is Linux? Understanding the Kernel, Distributions, and Open Source

Understand how the Linux kernel differs from a distribution, what user space and open source mean, and how to check your system's kernel and distribution versions.

Linux journalctl Command: Read systemd Logs

Linux journalctl Command: Read systemd Logs

Learn how to read systemd Logs with the Linux journalctl command, including practical examples, key options, and important precautions.

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Practice creating, copying, renaming, moving, and deleting files and directories in a dedicated folder while checking each result safely.

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.