开发者

how to see the content of a particular file in .tar.gz archive without unzipping the contents?

for ex abc.tar.gz has

abc/file1.txt

ab开发者_JAVA技巧c/file2.txt

abc/abc1/file3.txt

abc/abc2/file4.txt

i need to read/display the contents of file3.txt without extracting the file.

Thanks for any input.


import tarfile
spam = tarfile.open( "abc.tar.gz" )
if "abc/abc1/file3.txt" in spam.getnames():
    with spam.extractfile( "abc/abc1/file3.txt" ) as ham:
        print ham.read()

See tarfile.


tar -xzf mytar.tar.gz --to-command=cat filename.in.archive
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜