I am trying to zip up my application and would like to exclude all of my image directories apart from one.
Consider the following folder structure:
/images
│
└───/foo // exclude
│
└───/bar // exclude
│
└───/foobar // exclude
│
└───/icons // include
From what I understand, the zip command does not allow the use of regular expressions within it's arguments and as such, I am not sure what to do.
I have done some research and believe there is a way to use ls/find but I am not entirely sure how. Can anyone suggest how I can go about this?
This is my current command (excludes all image directories):
zip -rq application.zip . -x vendor/\* node_modules/\* .git/\* .env public/assets/images/\*
and I believe I need something like this (I haven't got the regex to actually work):
find ./public/assets/images -maxdepth 1 -regex '\.\/(?!icons).* | zip -rq application.zip . -x vendor/\* node_modules/\* .git/\* .env INSERT_FIND_RESULTS_HERE
Update
The full application directory looks similar to the following:
/www
│ .env
│ .env.example
│ .env.pipelines
│ .gitignore
│ artisan
│ etc...
│
└───/.ebextensions
└───/.git
└───/app
└───/bootstrap
└───/config
└───/database
└───/infrastructure
└───/node_modules
└───/public
│ │ .htaccess
│ │ index.php
│ │ etc...
│ │
│ └───/assets
│ │ └───/fonts
│ │ └───/images
│ │ │ └───/blog
│ │ │ └───/brand
│ │ │ └───/capabilities
│ │ │ └───/common
│ │ │ └───/contact
│ │ │ └───/icons
│ │ │ └───/misc
│ │ │ └───etc...
│ │
│ └───/js
│ └───/css
│
└───/storage
└───/tests
└───/vendor
I want to zip all of the files excluding:
vendor/
node_modules/
.git/
.env
public/assets/images/ (excluding public/assets/images/icons)
Update 2
Since posting, I have learned that find does not allow lookaheads in it's regular expressions and therefore I need to use a combination of grep and find. As such, this is my latest command (still not working though):
find ./public/assets/images -maxdepth 1 -regex '\./public/assets/images/.*' | grep -oP '\./public/assets/images/(?!icons).*' | xargs zip -rq application.zip . -x vendor/\* node_modules/\* .git/\* .env
Note, I don't know how to use xargs and I believe this is why the above does not work as intended.