Tar除具有特定名称的文件夹以外的所有文件夹和文件

时间:2022-04-05 22:55:44

Im trying to tar a folder with subdirectories but i want to exclude all folders with the name "log".

我试图tar子文件夹与子目录,但我想排除所有名称为“日志”的文件夹。

I have search and seen that the tar command have the option of --exclude the problem is that this option required to be specific folder not a dynamic one.

我有搜索并看到tar命令有选项--exclude问题是这个选项需要特定文件夹而不是动态文件夹。

Is there any other way?

还有其他方法吗?

so far the command i have is:

到目前为止我的命令是:

tar czf ROOT/backup/servers/20150504.tar.gz ./servers --exclude=".*log.*"

1 个解决方案

#1


If you want to exclude all folders with the name "log", probably using -X is more convenient. Here is an example:

如果要排除名为“log”的所有文件夹,可能使用-X更方便。这是一个例子:

$ find ./servers -type -d -name *log* > excludefiles
$ tar czf ROOT/backup/servers/20150504.tar.gz -X excludefiles ./servers

#1


If you want to exclude all folders with the name "log", probably using -X is more convenient. Here is an example:

如果要排除名为“log”的所有文件夹,可能使用-X更方便。这是一个例子:

$ find ./servers -type -d -name *log* > excludefiles
$ tar czf ROOT/backup/servers/20150504.tar.gz -X excludefiles ./servers