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*"

相关内容