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.









