开发者

List and Remove directories in an archive

开发者 https://www.devze.com 2022-12-28 03:25 出处:网络
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.

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

精彩评论

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