• No products in the cart.

DevOps on AWS – Python Scripts 9 : Tar file Operations


import tarfile, sys

    #open tarfile
tar = tarfile.open(sys.argv[1], “r:tar”)

    #present menu and get selection
selection = raw_input(“Entern
    1 to extract a filen
    2 to display information on a file in the archiven
    3 to list all the files in the archivenn”)

    #perform actions based on selection above
if selection == “1”:
    filename = raw_input(“enter the filename to extract:  “)
    if (filename.endswith(“tar”)):
tar = tarfile.open(filename)
print “Extracted in Current Directory”
elif selection == “2”:
    filename = raw_input(“enter the filename to inspect:  “)
    for tarinfo in tar:
        if tarinfo.name == filename:
             print “n  Filename:tt”, tarinfo.name, “n Size:tt”, tarinfo.size, “bytes”
elif selection == “3”:
print tar.list(verbose=True)
   # print “There was a problem running the program”

February 22, 2021

Contact Address

Rise ‘n’ Shine Technologies:
Third Floor, Plot No1(Part), near KPHB Metro Station, KPHB Bagyanagar Colony, Kukatpally Main road, Balanagar Mandal, Rangareddy Dist-500072

Landmarks : Above VIOLET & PURPLE, near PJR statue, kphb metro station

  8686 98 8042


All rights reserved.
error: Alert: Content is protected !!