LX0-103 · Question #201
Which of the following commands displays the contents of a gzip compressed tar archive?
The correct answer is B. tar ztf archive.tgz. The tar command with the z, t, and f flags lists the contents of a gzip-compressed archive without extracting it.
Question
Which of the following commands displays the contents of a gzip compressed tar archive?
Options
- Agzip archive.tgz | tar xvf -
- Btar ztf archive.tgz
- Cgzip -d archive.tgz | tar tvf -
- Dtar cf archive.tgz
How the community answered
(19 responses)- A5% (1)
- B95% (18)
Why each option
The tar command with the z, t, and f flags lists the contents of a gzip-compressed archive without extracting it.
This pipes gzip compression (not decompression) of the archive into tar, which is logically backwards and would not display contents.
The 'tar ztf archive.tgz' command uses the 'z' flag to invoke gzip decompression, 't' to list (table of contents) rather than extract, and 'f' to specify the archive file. This is the standard single-command approach for viewing gzip-compressed tar archive contents.
The 'gzip -d' command decompresses to a file by default rather than stdout, so piping to tar would fail without a '-c' flag, and this two-step approach is not correct syntax as written.
'tar cf' creates a new tar archive rather than listing contents, and it lacks both the 'z' flag for gzip and the 't' flag for listing.
Concept tested: Listing contents of gzip-compressed tar archives
Source: https://www.gnu.org/software/tar/manual/tar.html
Topics
Community Discussion
No community discussion yet for this question.