Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@r0b3r70

This comment has been minimized.

Copy link

@r0b3r70 r0b3r70 commented Jan 20, 2018

slightly modified to backup all my projects in www dir
$ zip -r www.zip www -x *.git* */node_modules/**\*

@se468

This comment has been minimized.

Copy link

@se468 se468 commented Feb 22, 2018

When it says no matches found: *.git*. Excludes the whole .git folder for the subdirectory. zip -r9 zipfile.zip directory -x directory/.git/\* directory/node_modules/\*

@runandrew

This comment has been minimized.

Copy link

@runandrew runandrew commented Nov 16, 2018

@se468 thanks for the info, couldn't figure out why I was getting that error. For my specific case I zipped a folder containing multiple subfolders that contained node_modules and used the following command

zip -r output.zip directory -x \*\*/\*/node_modules/\*
@DracoClaw

This comment has been minimized.

Copy link

@DracoClaw DracoClaw commented Apr 9, 2019

I think this might help me in what I am trying to do, I just dont understand how to use it.

@AlfredoDaAs

This comment has been minimized.

Copy link

@AlfredoDaAs AlfredoDaAs commented Nov 16, 2020

this really helps thanks!

@cy-park

This comment has been minimized.

Copy link
Owner Author

@cy-park cy-park commented Nov 16, 2020

Wow, I totally forgot that I had posted this, and now I think this might be my biggest contribution to internet. I will keep this post safe so that anyone can find this information whenever they need. Happy coding, y'all!

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