Zip 遞迴並排除某些目錄

Zip 遞迴並排除某些目錄

我想壓縮目錄但排除一些子目錄。假設我有這樣的結構:

directory
   subdirectory 1
   subdirectory 2
     project 1
       html
         directory 1 
         vendor
         node_modules
         ... (other directories)
     project 2
       html
         directory 2 
         vendor
         node_modules
         ... (other directories) 

我想壓縮整個主目錄,但我想排除這樣的路徑:

subdirectory2/*/html/vendor/**
subdirectory2/*/html/node_modules/**

在哪裡:

  • *- 是一級目錄
  • **- 是包含任何檔案和子目錄的目錄

問題是這些project 1project 2是非常動態的——它們有多個。另請注意,vendor目錄(理論上也是如此node_modules)可以放置在其他一些地方,例如,所以project 1/html/public/vendor我不想只排除vendor子目錄,而只排除vendor恰好位於專案的給定 html 目錄中的特定子目錄。

是否可以僅使用zip命令來製作如此複雜的事情,或者也許應該為此編寫一些 bash 腳本?

如果有什麼不同的話,我正在使用 MacOS。

到目前為止我所取得的成就是:

cd directory && zip test-zip.zip  * -r -T -x */*/html/vendor/** */*/html/node_modules/**

看起來它幾乎可以工作,但它創建了空的供應商和節點模組目錄(但不包括它們的內容)

答案1

看來解決方案是:

cd directory && 
zip test-zip.zip  * -r -T -x "*/*/html/vendor/" "*/*/html/node_modules/" "*/*/html/vendor/**" "*/*/html/node_modules/**"

所以我也排除了這個目錄和那些目錄中的所有內容,並將所有內容都用引號括起來,以便以有效的方式擴展

相關內容