nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    5% (1)
  • B
    95% (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.

Agzip archive.tgz | tar xvf -

This pipes gzip compression (not decompression) of the archive into tar, which is logically backwards and would not display contents.

Btar ztf archive.tgzCorrect

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.

Cgzip -d archive.tgz | tar tvf -

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.

Dtar cf archive.tgz

'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

#tar#gzip#archive#compression

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice