centos7のzip除外フォルダ

centos7のzip除外フォルダ

以下のコマンドを正常にテストしましたが成功しませんでした... CentOS 7から特定のサブディレクトリ(およびその中のすべてのファイル)をどのように除外しますか?

zip -r file.zip /var/www/html/ -x "/var/www/html/exclude1/" -x "/var/www/html/exclude2/" -x "/var/www/html/exclude3/"

zip -r file.zip /var/www/html/ -x /var/www/html/exclude1/**\* /var/www/html/exclude2/**\* /var/www/html/exclude3/**\*

zip -r file.zip /var/www/html/ -x /var/www/html/exclude1/ /var/www/html/exclude2/ /var/www/html/exclude2/

ベストアンサー1

正しい構文は次のとおりです。

zip -r file.zip /var/www/html/ -x "/var/www/html/exclude1*" "/var/www/html/exclude2*" "/var/www/html/exclude3*"

例:

以下にいくつかのディレクトリとファイルを作成しました/tmp/tozip。各ディレクトリにはtest.txtファイルが含まれています。

$ find /tmp/tozip/ -type d
/tmp/tozip/
/tmp/tozip/exclude
/tmp/tozip/fol1
/tmp/tozip/fol1/exclude
/tmp/tozip/fol2
/tmp/tozip/fol2/exclude
/tmp/tozip/fol3
/tmp/tozip/fol3/fol2
/tmp/tozip/fol3/fol2/fol1
/tmp/tozip/fol3/fol2/fol1/exclude

$ find /tmp/tozip/ -wholename '*exclude/*'
/tmp/tozip/exclude/test.txt
/tmp/tozip/fol1/exclude/test.txt
/tmp/tozip/fol2/exclude/test.txt
/tmp/tozip/fol3/fol2/fol1/exclude/test.txt

$ zip myzip.zip -r /tmp/tozip -x "/tmp/tozip/fol1/exclude*" "/tmp/tozip/fol2/exclude*" "/tmp/tozip/fol3/fol2/fol1/exclude*" "/tmp/tozip/exclude*"
  adding: tmp/tozip/ (stored 0%)
  adding: tmp/tozip/fol1/ (stored 0%)
  adding: tmp/tozip/fol1/test.txt (stored 0%)
  adding: tmp/tozip/fol2/ (stored 0%)
  adding: tmp/tozip/fol2/test.txt (stored 0%)
  adding: tmp/tozip/fol3/ (stored 0%)
  adding: tmp/tozip/fol3/fol2/ (stored 0%)
  adding: tmp/tozip/fol3/fol2/fol1/ (stored 0%)
  adding: tmp/tozip/fol3/fol2/fol1/test.txt (stored 0%)
  adding: tmp/tozip/fol3/fol2/test.txt (stored 0%)
  adding: tmp/tozip/fol3/test.txt (stored 0%)
  adding: tmp/tozip/test.txt (stored 0%)

私の郵便番号:

$ zip -help
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:

テストの機能:

mkdir -p /tmp/tozip/exclude /tmp/tozip/fol1/exclude /tmp/tozip/fol2/exclude  /tmp/tozip/fol3/fol2/fol1/exclude

find /tmp/tozip/ -type d -exec touch "{}/test.txt" \;

zip myzip.zip -r /tmp/tozip -x "/tmp/tozip/fol1/exclude*" "/tmp/tozip/fol2/exclude*" "/tmp/tozip/fol3/fol2/fol1/exclude*" "/tmp/tozip/exclude*"

おすすめ記事