【问题标题】:Excluding specific directory in tar using --exclude使用 --exclude 排除 tar 中的特定目录
【发布时间】:2022-01-12 22:15:50
【问题描述】:

想象以下目录结构:

tartest> find .
.
./node_modules
./foo
./foo/node_modules
./foo/foo.js

有没有办法使用 only tar(不是 find/xargs 解决方案)排除顶级 node_modules 而不是 foo 下的那个。

我原以为使用 ./node_modules 指定排除目录会起作用,但是

tartest> tar cvfz ../foo.tar.gz  --exclude='./node_modules' .
a .
a ./foo
a ./foo/foo.js

【问题讨论】:

  • 可能会根据您使用的tar 的版本而有所不同...您可以发布tar --version 吗?

标签: syntax tar macos-monterey


【解决方案1】:
tar cvfz ../foo.tar.gz  --exclude='^./node_modules' .

因为--exclude 采用了一个模式。 '^' 作为行首匹配是否适用于您的tar 版本还有待观察。

【讨论】:

  • 这适用于我的 MacOS 12.1-Monterey,bsdtar 3.5.1。
【解决方案2】:

我建议将cvfz 替换为cvzf

【讨论】:

    猜你喜欢
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2016-03-02
    • 2017-01-23
    • 2013-11-19
    • 1970-01-01
    相关资源
    最近更新 更多