A
cd ..
Tools

ZIP & Unzip Archives

Create, extract, and manage ZIP archives.

2025-11-24
zip, unzip, compression

Create ZIP archive

zip archive.zip file.txt
zip archive.zip file1.txt file2.txt file3.txt

ZIP directory

zip -r archive.zip directory/

Extract ZIP

unzip archive.zip

Extract to specific directory

unzip archive.zip -d /path/to/directory

List contents

unzip -l archive.zip

Test archive integrity

unzip -t archive.zip

Compression levels

# No compression (store only)
zip -0 archive.zip file.txt

# Fast compression
zip -1 archive.zip file.txt

# Maximum compression
zip -9 archive.zip file.txt

Password protection

#Create encrypted
zip -e archive.zip file.txt
# Will prompt for password

# Extract encrypted
unzip archive.zip
# Will prompt for password

Exclude files

# Exclude pattern
zip -r archive.zip directory/ -x "*.log"

# Exclude multiple patterns
zip -r archive.zip directory/ -x "*.log" "*.tmp"

# Exclude directory
zip -r archive.zip directory/ -x "directory/cache/*"

Add files to existing archive

zip archive.zip newfile.txt
zip -u archive.zip updatedfile.txt  # Update if newer

Delete from archive

zip -d archive.zip file.txt

Split archives

# Split into 100MB parts
zip -s 100m archive.zip -r directory/

# Join split archives
zip -F archive.zip --out complete.zip

Update archive

# Add only new/modified files
zip -u archive.zip -r directory/

# Freshen existing files only
zip -f archive.zip -r directory/

Verbose output

zip -v archive.zip file.txt
unzip -v archive.zip

Quiet mode

zip -q archive.zip file.txt
unzip -q archive.zip

Overwrite without prompting

unzip -o archive.zip

Never overwrite

unzip -n archive.zip

View specific file

unzip -p archive.zip file.txt | less

Extract specific files

unzip archive.zip file1.txt file2.txt
unzip archive.zip "*.txt"

Exclude on extract

unzip archive.zip -x "*.log"

Sync directories

# Archive with sync (delete removed files)
zip -FS archive.zip -r directory/

Date filter

# Archive only files modified after date
zip archive.zip -r directory/ -t 11/20/2025

Recurse symbolic links

zip -ry archive.zip directory/

Store paths

# No directory path
zip -j archive.zip directory/*

# With full path
zip archive.zip directory/file.txt

Pipe to ZIP

echo "content" | zip archive.zip -
tar cf - directory/ | zip archive.tar.zip -

Check if file exists in archive

unzip -l archive.zip | grep filename

Common scenarios

Backup directory

zip -r backup-$(date +%Y%m%d).zip /home/user/

Website deployment

zip -r website.zip public_html/ -x "*.git*" "*.cache*"

Archive with verification

zip -r archive.zip directory/ && unzip -t archive.zip

Compress all PDFs

zip documents.zip *.pdf

Performance comparison

# Fast (level 1)
time zip -1 -r fast.zip directory/

# Default (level 6)
time zip -r default.zip directory/

# Maximum (level 9)
time zip -9 -r max.zip directory/

Alternatives

# tar.gz (better compression for many files)
tar -czf archive.tar.gz directory/

# 7zip (best compression)
7z a -t7z archive.7z directory/

# rar (good compression, proprietary)
rar a archive.rar directory/

Was this useful?

Share with your team

Browse More