Zip a Folder While Excluding Files with -x

Compress a directory and skip junk files in the same command.

macOSZip & ArchivesFilesarchiveLow risk
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

RiskLow risk
!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 files
    ss64.com · technical · 2026-09-17
    Evidence: 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