Displaying Contents of a Gzip Compressed Tar Archive

Which Command Displays Contents of a Gzip Compressed Tar Archive?

Question

Which of the following commands displays the contents of a gzip compressed tar archive?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

B

The correct answer is B. tar ztf archive.tgz.

Explanation:

  • A. gzip archive.tgz | tar xvf - : This command uncompresses and extracts the contents of the archive.tgz file. The output is sent to the console. The problem with this command is that it only displays the contents of the uncompressed tar archive, not the compressed archive itself.

  • B. tar ztf archive.tgz: This command lists the contents of the gzip compressed tar archive, archive.tgz. The option "z" specifies that the archive is compressed with gzip, "t" specifies that we want to list the contents of the archive, and "f" specifies that the following argument is the filename of the archive.

  • C. gzip -d archive.tgz | tar tvf -: This command uncompresses the archive.tgz file and displays the contents of the uncompressed tar archive. The problem with this command is that it displays the uncompressed contents of the archive, not the compressed archive itself.

  • D. tar cf archive.tgz: This command creates a new gzip compressed tar archive named archive.tgz. It does not display the contents of an existing archive.

Therefore, the correct command to display the contents of a gzip compressed tar archive is "tar ztf archive.tgz".