开发者

List and Remove directories in an archive

I wonder how to list the content in an archive file and remove some directories from it?

For example, I have an archive file data.tar.

  1. I would like to list its content without extracting it.开发者_StackOverflow中文版 Is it possible to control the level of directory for viewing? I mean not necessarily every files, but just down to some level of the path.

  2. I also would like to remove some directories matching "*/count1000" from it.


to see the contents of the tar file,

tar tvf mytar.tar

to extract a file,

tar xvf mytar.tar myfile.txt

to delete a file

tar -f mytar.tar --delete */count1000


You can strip the 1st path component with:

cat myarchive.tar.gz | tar -tzf - | grep --only-matching -e "/.*"

You can strip the 2nd path component with:

cat myarchive.tar.gz | tar -tzf - | grep --only-matching -e "/.*/.*"

etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜