Home > Net >  zip a directory except all file and folders with a specific name
zip a directory except all file and folders with a specific name

Time:01-03

I know that I can do

zip -r archive.zip ./mydir -x ./mydir/dir_x/* ./mydir/dir_y/dir_z/dir_x/*

to exclude those two folders, but how can I exclude all directories and files by name and not by path?

CodePudding user response:

The -x option of zip is for filtering out filenames, you can't use it for excluding a directory.

A workaround is to list all the filepaths that you want to put in your zip archive; here's how you can do it with GNU/BSD find:

find mydir ! -type d ! -path '*/dir_x/*' |
zip archive.zip -@
  • Related