简体   繁体   English

Zip文件夹排除一些文件夹

[英]Zip folder exclude some folders

I'm trying to backup my www-folder but hidden folders like .config inside www are added to the backup. 我正在尝试备份我的www文件夹,但将www内部的.config之类的隐藏文件夹添加到了备份中。 I want to exclude the folder "backups" and all folders (and files) starting with a dot. 我想排除文件夹“备份”和所有以点开头的文件夹(和文件)。

The problem is that it copies all the hidden folders like .config to the zip-file. 问题在于它将所有隐藏的文件夹(如.config)复制到zip文件中。

Current code: 当前代码:

zip -r /var/www/backups/site/$(date +\%Y-\%m-\%d-\%H-\%M).zip /var/www -x "*backups*" "*.*" "*/.*"

这应该为您工作。

zip -r --exclude=*backups* --exclude=*/.* /var/www/backups/site/$(date +\%Y-\%m-\%d-\%H-\%M).zip /var/www

Use a linux find command with an exclude flag, then pipe it into zip. 使用带有exclude标志的linux find命令,然后将其传递到zip中。

The following command will exclude all paths under the current directory containing the keywords "backups" or files with "/." 以下命令将排除当前目录下包含关键字“ backups”或带有“ /”的文件的所有路径。 in the path and then pipe the files into zip. 在路径中,然后将文件通过管道传递到zip。

    find . | grep -v "\(backups\|/\.\)" | xargs zip archive.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM