zip Command
Beginner Compression & Archives man(1)Package and compress files into ZIP archives
👁 8 views
📅 Updated: Mar 15, 2026
SYNTAX
zip [OPTION]... ARCHIVE FILE...
What Does zip Do?
zip creates compressed archive files in the ZIP format, widely compatible across Windows, macOS, and Linux. Unlike tar+gzip, zip combines archiving and compression in one step.
zip is the best choice when creating archives that need to be opened on Windows or macOS, as ZIP is universally supported. For Linux-only use, tar.gz is generally preferred.
zip supports encryption, comments, splitting large archives, and compression levels. It can update existing archives by adding or replacing files.
zip is the best choice when creating archives that need to be opened on Windows or macOS, as ZIP is universally supported. For Linux-only use, tar.gz is generally preferred.
zip supports encryption, comments, splitting large archives, and compression levels. It can update existing archives by adding or replacing files.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -r | Recursively include directories | zip -r archive.zip directory/ |
| -e | Encrypt with password | zip -e secret.zip confidential.txt |
| -9 | Maximum compression | zip -9 archive.zip files/ |
| -x | Exclude files matching pattern | zip -r project.zip project/ -x '*.git*' '*.log' |
| -u | Update existing archive | zip -u archive.zip newfile.txt |
| -d | Delete files from archive | zip -d archive.zip unwanted.txt |
| -j | Junk (strip) directory paths | zip -j flat.zip /path/to/files/* |
| -s | Split into parts of specified size | zip -s 100m -r large.zip /data/ |
Practical Examples
#1 Create zip archive
Creates a zip file from a directory recursively.
$ zip -r project.zip project/#2 Zip with exclusions
Creates archive excluding git files, node_modules, and logs.
$ zip -r deploy.zip app/ -x '*.git*' 'node_modules/*' '*.log'#3 Password-protected zip
Creates an encrypted archive that requires a password to open.
$ zip -e sensitive.zip report.pdf data.xlsx#4 Maximum compression
Uses maximum compression for smallest file size.
$ zip -9r archive.zip documents/#5 Update archive
Adds or replaces a file in an existing archive.
$ zip -u archive.zip updated_file.txt#6 Zip without paths
Creates archive with files at the root (no directory structure).
$ zip -j photos.zip /home/user/photos/*.jpgTips & Best Practices
Use for cross-platform sharing: zip is the best format when sharing with Windows/macOS users. Use tar.gz for Linux-only archives.
zip encryption is weak: Standard zip encryption (ZipCrypto) is weak. For secure encryption, use 7z or GPG instead.
-x exclude syntax: Exclude patterns need quoting: zip -r arch.zip dir/ -x '*.log' '*.tmp' 'dir/cache/*'
Frequently Asked Questions
How do I create a zip file?
zip -r archive.zip directory/ creates a zip from a directory. Without -r, directories are not included recursively.
How do I password protect a zip?
zip -e archive.zip files. You will be prompted for a password. Note: standard zip encryption is not very secure.
Should I use zip or tar.gz?
Use zip for cross-platform sharing (Windows/macOS). Use tar.gz for Linux backups and distribution (better permission preservation).
Related Commands
More Compression & Archives Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →