Below is a quick-start cheat-sheet plus a couple of tips that are specific to macOS’s built-in /usr/bin/zip.
Everything works in Terminal the same way it does on Linux/BSD, but the flags can be easy to forget.
1. Basic syntax
bash
# Prompt for the password (safer)
zip -e archive.zip file1 file2 dir1 dir2
# One-liner that **shows** the password on the command line (NOT recommended)
zip -P "MyS3cret!" archive.zip file1 file2 dir1 dir2
Flag
Meaning
-e
Encrypt. You’ll be asked for the password twice. (Legacy ZipCrypto, see “Security note” below.)
-r
Recurse into directories. Needed only if you pass directories and want their contents.
-P
Provide the password on the command line instead of being prompted. Insecure—shows up in shell history and ps output.
Example with recursion:
bash
zip -er project.zip README.md src/ docs/
You will be prompted:
code
Enter password:
Verify password:
2. Compress multiple unrelated paths but keep them tidy
bash
zip -er ~/Desktop/backup_$(date +%F).zip \
"$HOME/Documents/report.pdf" \
"$HOME/Pictures/2024/Trip/" \
"/Users/$USER/Library/Keychains/"
macOS path expansion works the same; just quote paths with spaces.
3. Updating or appending later
bash
# Add more files into an existing encrypted archive and keep encryption
zip -u -e archive.zip newfile1 newdir/
-u = update; -e will prompt again (you can press Enter twice to reuse the same password in most builds).
4. Splitting into volumes (optional)
bash
# Create 100-MiB chunks, encrypted
zip -er -s 100m bigstuff.zip Movies/BigClip.mov
# Results: bigstuff.z01, bigstuff.z02, …, bigstuff.zip
-s size letters: k kilobytes, m megabytes, g gigabytes.
5. Security caveat 🚨
• The built-in zip uses the legacy “ZipCrypto” scheme.
• For casual sharing it’s fine, but it isn’t strong (easily crackable with modern GPUs).
• For robust encryption, consider:
zip -er ARCHIVE.zip … # Prompted password, recursive if you include -r
zip -e file.zip file1 … # Encrypt, no recursion
zip -P "pw" … # Inline password (avoid)
zip -u … # Update existing zip
zip -s 64m -er … # Split into 64-MB parts, encrypted
That’s all you need to pack multiple files with a password on macOS’s command line 🚀.