LPIC-1 GNU and Unix Commands Practice Question
Which TWO commands can be used to view the contents of a compressed file named archive.tar.gz without extracting it to disk?
⚠ Common exam trap
It's easy for candidates to confuse `gunzip -l` (which shows compression metadata) with listing the actual file contents, or they mistakenly apply bzip2 tools to gzip archives, forgetting that each compression format requires its own specific decompression utility.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
tar -tzf archive.tar.gz
Option C, `tar -tzf archive.tar.gz`, is correct because the `-t` flag lists the archive contents, `-z` tells tar to filter through gzip, and `-f` specifies the archive file, so it lists the members of the gzipped tarball without writing them to disk. Option E, `zcat archive.tar.gz | tar -t`, is correct because `zcat` decompresses the gzip stream to standard output and pipes it into `tar -t`, which lists the archive contents from stdin without extracting files to disk. Option A, `gzip -d archive.tar.gz`, is wrong because `-d` decompresses the file, replacing it with `archive.tar` on disk rather than merely viewing contents. Option B, `bunzip2 -c archive.tar.gz | tar -t`, is wrong because `bunzip2` handles bzip2 compression, not gzip, so it cannot decompress a `.tar.gz` file. Option D, `gunzip -l archive.tar.gz`, is wrong because `gunzip -l` lists compression statistics for the gzip file itself, not the contents of the tar archive inside it.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
gzip -d archive.tar.gz
Why it's wrong here
gzip -d decompresses the archive to disk, creating archive.tar and deleting the .gz, which is extraction rather than viewing. It is tempting because gzip handles the compression layer, but listing members requires tar -t reading from stdin, as in gzip -dc archive.tar.gz | tar -t.
- ✗
bunzip2 -c archive.tar.gz | tar -t
Why it's wrong here
bunzip2 decompresses bzip2 data, not gzip, so it cannot read a .tar.gz stream and errors before tar runs. It is tempting because the -c pipe to tar -t is the correct viewing pattern; substituting bzip2 -dc would work for archive.tar.bz2 instead.
- ✓
tar -tzf archive.tar.gz
Why this is correct
The `-t` flag lists archive contents, while `-z` pipes through gzip decompression and `-f` specifies the filename, so `tar -tzf archive.tar.gz` reads and decompresses the gzip stream in memory. This satisfies the stem's constraint of viewing contents without extracting anything to disk.
- ✗
gunzip -l archive.tar.gz
Why it's wrong here
gunzip -l lists the compressed file's own metadata, such as uncompressed size and ratio, not the tar members inside. It is tempting because -l suggests listing, but viewing archive contents requires decompressing the stream into tar -t, for example gunzip -c archive.tar.gz | tar -t.
- ✓
zcat archive.tar.gz | tar -t
Why this is correct
Piping through zcat decompresses the gzip stream to stdout, which tar reads from standard input; the -t flag then lists archive members without writing them to disk. This satisfies the stem's requirement to view contents without extraction, though the pipeline is redundant since tar -tzf does both steps directly.
Go deeper
Related to this question
About these practice questions
This LPIC-1 question is part of Courseiva's 402-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.