Skip to content
DeveloperMemos

How to Compress a Folder to ZIP on macOS Using Terminal

macOS, Terminal, Bash, ZIP, File Management1 min read

If you're tired of using Finder to create ZIP files, the Terminal offers a faster and more flexible way to compress folders. Let's dive into the essential commands you'll actually use day-to-day.

Basic Zip Command

Want to zip up a folder quickly? Here's your go-to command:

1zip -r archive.zip folder_name

The -r flag tells zip to include everything in the folder, including all subfolders.

Useful Options

Here are some time-saving options I use regularly:

  1. Skip Those Pesky Hidden Files (-X):
1zip -r -X archive.zip folder_name
  1. Watch the Progress (-v):
1zip -r -v archive.zip folder_name
  1. Control Compression Level (-[0-9]):
1zip -r -9 archive.zip folder_name # Maximum compression
2zip -r -1 archive.zip folder_name # Fastest compression

Excluding Files

Need to leave out certain files? This command is your friend:

1zip -r archive.zip folder_name -x "*.DS_Store" "*/\.*"

This keeps your archives clean by excluding .DS_Store files and other hidden junk.

Updating Existing Archives

Got new changes? Update your ZIP without recreating the whole thing:

1zip -ru archive.zip folder_name

The -u flag is smart - it only updates files that have changed.

Best Practices

  1. Always use -r for folders (you'll thank me later)
  2. Put quotes around filenames with spaces
  3. Use -v for big folders so you're not left wondering if it's working
  4. Add -X to avoid macOS system file crud

Checking the Archive

Before sending that ZIP file off, double-check what's inside:

1unzip -l archive.zip

Quick Tip

Keep these commands handy in your shell history - they'll save you countless clicks through Finder. And remember, while GUI tools are fine, mastering these Terminal commands gives you way more control over your archives.