删除 tar 中的文件,带有通配符和异常

发布于 2024-09-27 08:45:49 字数 487 浏览 1 评论 0原文

我有一个 tarball,我想删除其中的所有 .tcl、.bat 、 .log 文件除了 pkgIndex.tcl。

如果我这样做,

tar --delete -f mytarball.tar --wildcards *{.tcl,.log,.bat}

我的 pkgIndex.tcl 将被删除,如何将其作为例外放入我的模式通配符中?

刚刚尝试过

tar  --delete -f mytarball.tar --wildcards *{.tcl,.log}  --exclude=*pkgIndex.tcl

,但

tar  --delete -f mytarball.tar --wildcards *{.tcl,.log}  --exclude=pkgIndex.tcl

没有成功...

I have a tarball, and i want to remove all .tcl, .bat , .log files except pkgIndex.tcl in it.

if i do

tar --delete -f mytarball.tar --wildcards *{.tcl,.log,.bat}

my pkgIndex.tcl will be deleted, how to put that as exception in my pattern wildcard?

Just tried

tar  --delete -f mytarball.tar --wildcards *{.tcl,.log}  --exclude=*pkgIndex.tcl

and

tar  --delete -f mytarball.tar --wildcards *{.tcl,.log}  --exclude=pkgIndex.tcl

To no avail...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-10-04 08:45:49

看起来当您使用 --delete 时,GNU tar 会忽略 --exclude 。

您可以执行 tar tf mytarball.tar --wildcards *{.tcl,.log} | grep -v pkgIndex.tcl | | grep -v pkgIndex.tcl | tar --delete -f mytarball.tar -T - 代替。这将列出所有匹配 *.tcl 或 *.log 的文件,grep 查找除 pkgIndex.tcl 之外的所有文件,并将列表通过管道返回到 tar,这将从 tarball 中删除这些文件。

Looks like GNU tar ignores --exclude when you use --delete.

You can do tar tf mytarball.tar --wildcards *{.tcl,.log} | grep -v pkgIndex.tcl | tar --delete -f mytarball.tar -T - instead. That will list all of the files matching *.tcl or *.log, grep for everything but pkgIndex.tcl, and pipe the list back into tar which will remove those files from the tarball.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文