Answers for "extract a tgz file"

4

how to extract tgz file in linux

tar zxvf file_name.tgz

where,
-z : Uncompress the resulting archive with gzip command
-x : Extract to disk from the archive
-v : Produce verbose output i.e. show progress and file names while extracting files
-f backup.tgz : Read the archive from the specified file called backup.tgz
Posted by: Guest on October-13-2020
0

extract tgz files in python

import os, sys, tarfile

def extract(tar_url, extract_path='.'):
    print tar_url
    tar = tarfile.open(tar_url, 'r')
    for item in tar:
        tar.extract(item, extract_path)
        if item.name.find(".tgz") != -1 or item.name.find(".tar") != -1:
            extract(item.name, "./" + item.name[:item.name.rfind('/')])
try:

    extract(sys.argv[1] + '.tgz')
    print 'Done.'
except:
    name = os.path.basename(sys.argv[0])
    print name[:name.rfind('.')], '<filename>'
Posted by: Guest on November-14-2020

Browse Popular Code Answers by Language