Example 1
Extract Archive to Current Directory
$ unzip archive.zip
Archive: archive.zip
inflating: file1.txt
inflating: file2.txt
inflating: folder/file3.txt
Extracts all files from a ZIP archive to the current directory. This is the most basic and commonly used form of unzip. Files are extracted with their original directory structure preserved. If files already exist, unzip will prompt before overwriting.
Default Behavior: Preserves directory structure and prompts before overwriting
Example 2
Extract to Specific Directory
$ unzip archive.zip -d /path/to/destination
Archive: archive.zip
inflating: /path/to/destination/file1.txt
inflating: /path/to/destination/file2.txt
inflating: /path/to/destination/folder/file3.txt
Extracts the archive to a specific directory using the '-d' option. The destination directory will be created if it doesn't exist. This is essential when you want to organize extracted files in a specific location rather than cluttering the current directory.
Auto-Create: The destination directory is automatically created if it doesn't exist
Example 3
List Archive Contents Without Extracting
$ unzip -l archive.zip
Archive: archive.zip
Length Date Time Name
--------- ---------- ----- ----
1024 2025-10-18 10:45 file1.txt
2048 2025-10-18 10:46 file2.txt
512 2025-10-18 10:47 folder/file3.txt
--------- -------
3584 3 files
Lists the contents of a ZIP archive without extracting anything using the '-l' option. Shows file names, sizes, and modification dates. Perfect for inspecting archive contents before extraction or verifying what's inside without unpacking.
Inspection: Always check archive contents before extracting to unknown locations
Example 4
Extract Specific File from Archive
$ unzip archive.zip file1.txt
Archive: archive.zip
inflating: file1.txt
Extracts only a specific file from the archive by naming it after the archive filename. You can specify multiple files by listing them separated by spaces. Useful when you only need certain files from a large archive without extracting everything.
Pattern Matching: Can also use wildcards like *.txt to extract matching files
Example 5
Extract Files with Pattern Matching
$ unzip archive.zip "*.txt"
Archive: archive.zip
inflating: file1.txt
inflating: file2.txt
inflating: folder/readme.txt
Extracts only files matching a specific pattern using wildcards. The pattern must be quoted to prevent shell expansion. This is extremely useful for extracting only specific file types (like all text files, images, or documents) from an archive.
Selective Extract: Use patterns like "*.jpg", "*.pdf", or "docs/*" for targeted extraction
Example 6
Overwrite Files Without Prompting
$ unzip -o archive.zip
Archive: archive.zip
inflating: file1.txt
inflating: file2.txt
inflating: folder/file3.txt
Overwrites existing files without prompting using the '-o' option. By default, unzip asks before overwriting. This option is useful in automated scripts or when you know you want to replace all existing files with archive versions.
Caution: Use carefully - this will overwrite files without warning!
Example 7
Never Overwrite Existing Files
$ unzip -n archive.zip
Archive: archive.zip
inflating: newfile.txt
skipping: file1.txt (file already exists)
skipping: file2.txt (file already exists)
Skips extraction of files that already exist using the '-n' option (never overwrite). Existing files are left untouched and only new files are extracted. Useful when you want to add new files from an archive without disturbing existing ones.
Safe Mode: Prevents accidental data loss by preserving existing files
Example 8
Quiet Mode - Suppress Output
$ unzip -q archive.zip
# No output unless there's an error
Runs unzip in quiet mode using the '-q' option, suppressing normal output messages. Only error messages are displayed. Perfect for scripts where you don't want extraction progress cluttering logs, or for cleaner automated processes.
Scripting: Combine with exit status checking for clean, automated extraction
Example 9
Test Archive Integrity
$ unzip -t archive.zip
Archive: archive.zip
testing: file1.txt OK
testing: file2.txt OK
testing: folder/file3.txt OK
No errors detected in compressed data of archive.zip.
Tests the integrity of a ZIP archive without extracting using the '-t' option. Verifies that the archive is not corrupted and all files can be successfully decompressed. Essential for validating downloads or checking archive health before extraction.
Verification: Always test archives after downloading to ensure data integrity
Example 10
Extract with Verbose Output
$ unzip -v archive.zip
Archive: archive.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
1024 Defl:N 512 50% 2025-10-18 10:45 12345678 file1.txt
2048 Defl:N 1024 50% 2025-10-18 10:46 87654321 file2.txt
512 Stored 512 0% 2025-10-18 10:47 abcdef12 folder/file3.txt
-------- ------- --- -------
3584 2048 43% 3 files
Displays detailed information about archive contents using the '-v' option (verbose). Shows compression method, compressed size, compression ratio, CRC checksums, and dates. More detailed than '-l', useful for analyzing compression efficiency and file details.
Detailed Info: Shows compression methods (Defl:N = deflated, Stored = no compression)
Bonus 1
Extract Password-Protected Archive
$ unzip -P mypassword archive.zip
Archive: archive.zip
inflating: sensitive.txt
inflating: confidential.doc
# Better approach - prompt for password:
$ unzip archive.zip
[archive.zip] sensitive.txt password:
Extracts password-protected archives using the '-P' option followed by the password. However, this is insecure as the password appears in command history and process listings. Better practice is to omit -P and let unzip prompt for the password, which hides it from logs and history.
Security: Never use -P in scripts or shared systems - password will be visible!
Bonus 2
Extract Multiple Archives
$ unzip '*.zip'
Archive: archive1.zip
inflating: file1.txt
Archive: archive2.zip
inflating: file2.txt
Archive: archive3.zip
inflating: file3.txt
# Or in a loop with destinations:
$ for zip in *.zip; do
unzip -q "$zip" -d "${zip%.zip}"
done
Extracts multiple ZIP archives in a single command or loop. The quoted wildcard extracts all zip files in the current directory. The loop example creates a separate directory for each archive named after the archive (without .zip extension). Essential for batch processing of multiple archives.
Batch Processing: Automate extraction of multiple archives with proper organization
Reference
unzip Command Options Quick Reference
Basic Extraction:
unzip archive.zip Extract to current directory
unzip archive.zip -d dir Extract to specific directory
Listing and Testing:
unzip -l archive.zip List contents (short format)
unzip -v archive.zip List contents (verbose)
unzip -t archive.zip Test archive integrity
Selective Extraction:
unzip archive.zip file.txt Extract specific file
unzip archive.zip "*.txt" Extract files matching pattern
unzip archive.zip dir/* Extract specific directory
Overwrite Control:
unzip -o archive.zip Overwrite without prompting
unzip -n archive.zip Never overwrite existing files
unzip -u archive.zip Update (extract if newer)
unzip -f archive.zip Freshen (overwrite if exists)
Output Control:
unzip -q archive.zip Quiet mode (suppress output)
unzip -qq archive.zip Very quiet (errors only)
Special Options:
unzip -P password archive.zip Password-protected archive
unzip -j archive.zip Junk paths (no directories)
unzip -C archive.zip Case-insensitive matching
unzip -a archive.zip Auto-convert text files
unzip -L archive.zip Convert to lowercase names
Common Patterns:
# Extract and organize
unzip archive.zip -d extracted/
# Check before extracting
unzip -l archive.zip | grep "\.txt$"
# Test multiple archives
unzip -t *.zip
# Extract all zip files to separate dirs
for f in *.zip; do unzip -q "$f" -d "${f%.zip}"; done
# Extract specific file types
unzip archive.zip "*.jpg" "*.png" -d images/
# Safe extraction (no overwrite)
unzip -n archive.zip
# Extract with error handling
if unzip -tq archive.zip; then
unzip -q archive.zip -d output/
echo "Extraction successful"
else
echo "Archive is corrupted"
fi
Exit Codes:
0 Success
1 Warning errors
2 Error in archive
3 Severe error
Related Commands:
zip Create ZIP archives
zipinfo Detailed archive information
7z Universal archive tool
tar Tape archive (tar.gz files)
Tips:
- Always test archives after downloading: unzip -t file.zip
- Check contents before extracting: unzip -l file.zip
- For sensitive archives, let unzip prompt for password
- Use -d to avoid cluttering current directory
- Combine with find for recursive archive processing
Comprehensive reference for unzip command including all common options, patterns, exit codes, and best practices for extracting and managing ZIP archives.