zip exclui pastas no centos7

1

eu testei os seguintes comandos abaixo, mas sem sucesso ... Como posso excluir subdiretórios específicos (e todos os arquivos dentro deles) no 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/
    
por eazy 26.10.2017 / 07:49

1 resposta

1

A sintaxe correta é a seguinte:

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

Exemplo:

Eu criei alguns diretórios e arquivos em /tmp/tozip , cada diretório contém um arquivo 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%)

Meu zip:

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

Teste para o op executar:

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*"
    
por 26.10.2017 / 08:17

Tags