[英]how to see the content of a particular file in .tar.gz archive without unzipping the contents?
對於前abc.tar.gz有
ABC / FILE1.TXT
ABC / FILE2.TXT
ABC / ABC1 / file3.txt
ABC / ABC2 / file4.txt
我需要讀取/顯示file3.txt的內容而不解壓縮文件。
感謝您的任何意見。
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()
請參閱tarfile 。
tar -xzf mytar.tar.gz --to-command=cat filename.in.archive
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.