tar --exclude不排除。为什么?

阿提奥布

我在bash脚本中有一条非常简单的代码行,它可以成功执行(即生成_data.tar文件),但它不会排除通过--exclude选项被告知为排除的子目录

/bin/tar -cf /home/_data.tar  --exclude='/data/sub1/*'  --exclude='/data/sub2/*' --exclude='/data/sub3/*'  --exclude='/data/sub4/*'  --exclude='/data/sub5/*'  /data

相反,它将生成一个_data.tar文件,其中包含/ data下的所有内容,包括我要排除的子目录中的文件。

知道为什么吗?以及如何解决这个问题?

更新我根据下面第一个答案中提供的链接实现了我的观察结果(顶层dir首先,最后一个排除后没有空格):

/bin/tar -cf /home/_data.tar  /data  --exclude='/data/sub1/*'  --exclude='/data/sub2/*'  --exclude='/data/sub3/*'  --exclude='/data/sub4/*'  --exclude='/data/sub5/*'

但这没有帮助。所有“排除的”子目录都存在于结果_data.tar文件中。

这令人费解。无论这是当前tar中的错误(CentOS 6.2,Linux 2.6.32上的GNU tar 1.23)还是tar对空白和其他易于忽略的错别字的“极端敏感性”,我都认为这是一个错误。目前。

这太可怕了:我尝试了以下建议的见解(无尾随/*),但在生产脚本中仍然不起作用:

/bin/tar -cf /home/_data.tar  /data  --exclude='/data/sub1'  --exclude='/data/sub2'  --exclude='/data/sub3'  --exclude='/data/sub4'

除了引号和2个空格(而不是1),我看不到我尝试过的内容与@Richard Perrin所做的任何区别。我将尝试这种方式(必须等待每晚运行的脚本作为要备份的目录)数量庞大)并进行报告。

/bin/tar -cf /home/_data.tar  /data --exclude=/data/sub1 --exclude=/data/sub2 --exclude=/data/sub3 --exclude=/data/sub4

我开始认为所有这些tar --exclude敏感度不是焦油而是环境中的某种东西,但是那又会是什么呢?

有效!最后一个变体尝试了工作(没有单引号和单空格,而不是--excludes之间的双倍空格)。很奇怪,但是接受。

逆天!事实证明,tar仅当顶级目录位于命令行的最后时才会排除(1.15.1)的较早版本这与1.23版的要求完全相反。供参考。

佩林

如果要排除整个目录,则模式应匹配该目录,而不是其中的文件。使用--exclude=/data/sub1代替--exclude='/data/sub1/*'

引用这些模式时要小心,以防止它们受到外壳扩展的影响。

参见以下示例,在最终调用中遇到了麻烦:

$ for i in 0 1 2; do mkdir -p /tmp/data/sub$i; echo foo > /tmp/data/sub$i/foo; done
$ find /tmp/data
/tmp/data
/tmp/data/sub2
/tmp/data/sub2/foo
/tmp/data/sub0
/tmp/data/sub0/foo
/tmp/data/sub1
/tmp/data/sub1/foo
$ tar -zvcf /tmp/_data.tar /tmp/data --exclude='/tmp/data/sub[1-2]'
tar: Removing leading `/' from member names
/tmp/data/
/tmp/data/sub0/
/tmp/data/sub0/foo
$ tar -zvcf /tmp/_data.tar /tmp/data --exclude=/tmp/data/sub[1-2]
tar: Removing leading `/' from member names
/tmp/data/
/tmp/data/sub0/
/tmp/data/sub0/foo
$ echo tar -zvcf /tmp/_data.tar /tmp/data --exclude=/tmp/data/sub[1-2]
tar -zvcf /tmp/_data.tar /tmp/data --exclude=/tmp/data/sub[1-2]
$ tar -zvcf /tmp/_data.tar /tmp/data --exclude /tmp/data/sub[1-2]
tar: Removing leading `/' from member names
/tmp/data/
/tmp/data/sub2/
/tmp/data/sub2/foo
/tmp/data/sub0/
/tmp/data/sub0/foo
/tmp/data/sub2/
tar: Removing leading `/' from hard link targets
/tmp/data/sub2/foo
$ echo tar -zvcf /tmp/_data.tar /tmp/data --exclude /tmp/data/sub[1-2]
tar -zvcf /tmp/_data.tar /tmp/data --exclude /tmp/data/sub1 /tmp/data/sub2

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么tar --exclude =“。*”创建一个空的存档?

来自分类Dev

为什么R使用系统tar,而不使用Rtools tar?

来自分类Dev

tar-排除某些文件

来自分类Dev

获取tar以排除某些文件

来自分类Dev

tar unix不更改目录

来自分类Dev

tar / gzip为什么不压缩两个相似的大目录?

来自分类Dev

TAR不喜欢什么角色?

来自分类Dev

tar -A和tar -r有什么区别?

来自分类Dev

与MacOS tar相比,为什么使用Python的tar库时tar.xz文件小15倍?

来自分类Dev

tar --excludes选项仅排除当前工作目录中的目录,而不排除子目录

来自分类Dev

排除tar.gz中的文件

来自分类Dev

排除tar中特定文件以外的文件

来自分类Dev

使用tar时无法排除目录

来自分类Dev

尝试创建TAR存档,但排除.messages文件

来自分类Dev

tar排除特定路径上的错误输出

来自分类Dev

tar 排除在 bash 中不起作用

来自分类Dev

为什么我无法解压缩.tar.bz2或.tar.xz文件?

来自分类Dev

带有--exclude-cache的GNU tar无法排除包含CACHEDIR.TAG文件的目录

来自分类Dev

tar“ --exclude-from”双星通配符

来自分类Dev

tar --exclude '*/logs' 不起作用

来自分类Dev

为什么“ tar”试图创建一个空的存档?

来自分类Dev

为什么tar输出上的gzip总是产生不同的结果?

来自分类Dev

为什么选项的特定顺序对tar命令很重要?

来自分类Dev

为什么参数序列会影响tar的执行?

来自分类Dev

为什么tar -c命令从成员名称中删除前导“ /”

来自分类Dev

tar检查点与输入不匹配

来自分类Dev

提取tar文件而不覆盖工作目录

来自分类Dev

什么是打开.tar文件的正确软件?

来自分类Dev

传递给tar命令的参数是什么?

Related 相关文章

热门标签

归档