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
.
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.
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.
精彩评论