Skip to content

Instantly share code, notes, and snippets.

  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ldong/15ee0b1faa121891e9b53dddcefa0ca0 to your computer and use it in GitHub Desktop.
Zip excluding specific directories and files

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*

Number parameter means degree of compression. -9 is the most optimal but the slowest compression. If -0 is given, there will be no compression. Default level is -6.

** means to adapt exclusions recursively inner directories. \* is an escaped wildcard to avoid path expansion.

Copy link

Rho-bur commented Dec 18, 2021

Should be zip -r9 [target_file] [source_file] -x *.git* -x node_modules/\* and zip -r9 [target_file] [source_file] -x *.git* -x node_modules/**\*

Copy link

I'm using Ubuntu 20.04. In my case I only need to use -x once for two patterns to get excluded.

Copy link

forme this is the work
zip -r dockerexpress dockerexpress -x 'node_modules/*'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment