Zip a Folder While Excluding Files with -x
Compress a directory and skip junk files in the same command.
Append -x followed by quoted patterns to the normal zip -r command to leave those files out.
01Command
Command
$ zip -r project.zip ~/Desktop/Project/ -x "*.log" "*.DS_Store" "*/.git/*"02What it does
Patterns match the paths as they are stored in the archive, so "*/.git/*" strips the whole git folder while "*.log" removes logs anywhere in the tree. Quote every pattern or the shell will expand it before zip sees it — then you get a clean project bundle without building a separate copy first.
03Risk
!Warning: Excluded files stay on disk untouched — only the archive omits them.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- zip – Package and compress filesEvidence: zip -x excludes paths matching the given shell patterns; patterns match the paths as stored inside the archive.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
Find files larger than 500 MB on Mac
List the biggest files in your home folder that are eating disk space.
Show file extensions for all files on Mac
Make Finder display .pdf, .docx, .png and every other extension at all times.
Create a password-protected zip on Mac
Encrypt a folder or files into a password-protected archive from Terminal.