LFCS · Question #801
Which of the following commands displays the contents of a gzip compressed tar archive?
The correct answer is B. tar ztf archive.tgz. To display the contents of a gzip compressed tar archive, use the tar command with the z (gzip), t (list), and f (file) options.
Question
Options
- Agzip archive.tgz | tar xvf -
- Btar ztf archive.tgz
- Cgzip -d archive.tgz | tar tvf -
- Dtar cf archive.tgz
How the community answered
(37 responses)- B92% (34)
- C5% (2)
- D3% (1)
Why each option
To display the contents of a gzip compressed tar archive, use the `tar` command with the `z` (gzip), `t` (list), and `f` (file) options.
`gzip archive.tgz` would attempt to re-compress an already compressed file or incorrectly handle the pipe, and `xvf -` would extract, not just list, if it even received input.
The command `tar ztf archive.tgz` efficiently displays the table of contents (`t`) of a specified archive file (`f`) that has been compressed with gzip (`z`), without extracting its contents.
`gzip -d archive.tgz` without `-c` decompresses to a file named `archive.tar` (or similar) in the current directory and does not send output to stdout for piping; therefore, this command sequence is functionally incorrect for piping.
`tar cf archive.tgz` is used to create (`c`) a tar archive (`f`) from files, not to display the contents of an existing one.
Concept tested: tar command (gzip, list contents)
Source: https://www.gnu.org/software/tar/manual/tar.html
Topics
Community Discussion
No community discussion yet for this question.