January 2019
Beginner
318 pages
8h 23m
English
In this section, we will learn about how we can examine the contents of a created tar archive without actually extracting that tar file. We will do it using Python's tarfile module.
Create a examine_tar_file_content.py script and write the following content in it:
import tarfiletar_file = tarfile.open("work.tar.gz", "r:gz")print(tar_file.getnames())
Run the script as follows:
$ python3 examine_tar_file_content.pyOutput:['welcome.py', 'hello.py', 'hello.txt', 'sample.txt', 'sample1.txt']
In previous example, we used the tarfile module to examine the contents of the created tar file. We used the getnames() function to read the data.
Read now
Unlock full access