2

I have a lot of directories in the initial folder and I want to zip everything , but exclude all the node_modules folder of each directory , I tried this:

zip -r all_repos.zip . -x '*node_modules*'

But it doesn't exclude all sub-folders.

Any idea how to do it recursively ?

JAN
  • 145

1 Answers1

2

zip looks at files, so to make it include directories you need to add /\* or '/*' according to these instructions about 'include' in `man zip'

          Examples are for Unix unless otherwise specified.]  So to include dir,
          a directory directly  under  the current directory, use
             zip -r foo . -i dir/\*

      or

             zip -r foo . -i "dir/*"

So let us assume it works to 'exclude' too, and try with

zip -r all_repos.zip . -x '*node_modules*/*'
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • 1
    Thanks! zip -r ~/code_with_node_modules_excluded.zip ~/code/ -x '*node_modules*/*' -x '*vendor*/*' -x '*.cache*/*' -x '*.next*/*' -x '*target*/*' was very helpful for me. 32G down to just 1.1G! (according to cd ~/code/ && du -aBM 2>/dev/null | sort -nr | head -n 10 and du --max-depth=0 -h ~/code) – Ryan Jan 09 '23 at 22:05