开发者

Remove file in a tar, with wildcard and exception

开发者 https://www.devze.com 2023-01-20 09:03 出处:网络
I have a tarball, and i want to remove all .tcl, .bat , .log files except pkgIndex.tcl in it. if i do

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

精彩评论

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

关注公众号