开发者

Remove file in a tar, with wildcard and exception

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开发者_Python百科.tar --wildcards *{.tcl,.log}  --exclude=pkgIndex.tcl

To no avail...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜