Courseiva
Essential Commands →mediumMultiple Select

How to View a .gz File Without Decompressing

Which THREE of the following commands can be used to view the contents of a compressed file named 'file.gz' without permanently decompressing it? (Choose exactly three.)

Quick Answer

The correct commands are `zless`, `zmore`, and `zcat`, as all three allow you to view a compressed .gz file without permanently decompressing it. These utilities work by decompressing the file on the fly and piping the output to a pager or standard output, leaving the original `file.gz` untouched on disk. On the LFCS exam, this tests your understanding of the `z*` family of commands, which are often confused with their uncompressed counterparts—a common trap is assuming `less` or `more` can directly read gzip files, but they cannot. Remember that `zcat` sends output to the terminal (like `cat`), `zless` provides scrollable viewing (like `less`), and `zmore` pages through content (like `more`). A handy memory tip: think of the prefix "z" as "zipped," so `zcat`, `zless`, and `zmore` are simply the zipped versions of `cat`, `less`, and `more`.

⚠ Common exam trap

The trap here is that candidates mistakenly think `gunzip` or `gzip` can be used to view file contents without permanent decompression, confusing compression/decompression commands with viewing utilities like `zcat`, `zmore`, and `zless`.

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

✓

zmore file.gz

Option B (zmore file.gz) is correct because zmore is a filter that pipes the decompressed output of gzip-compressed files through more, letting you page through the contents without writing a decompressed file to disk. Option D (zcat file.gz) is correct because zcat decompresses the file to standard output, displaying its contents on screen while leaving the original file.gz intact. Option E (zless file.gz) is correct because zless uses less to page through the decompressed stream of a gzip file, again without permanently decompressing it. Option A (gzip file.gz) is wrong because gzip is used to compress files (and would actually try to compress file.gz further), not to view contents. Option C (gunzip file.gz) is wrong because gunzip permanently decompresses the file, replacing file.gz with an uncompressed file, which is exactly what the question excludes.

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 file.gz

    Why it's wrong here

    gzip compresses files; given an already-compressed file.gz it either reports the suffix or recompresses, and it never writes decompressed content to stdout. It would be the right tool to create file.gz from an uncompressed source, which is the opposite of viewing contents without permanent decompression.

  • ✓

    zmore file.gz

    Why this is correct

    zmore pipes the gzip stream through a pager, decompressing on the fly to standard output while leaving file.gz untouched on disk. That satisfies the constraint of viewing contents without permanently decompressing, and it paginates long output.

  • ✗

    gunzip file.gz

    Why it's wrong here

    gunzip decompresses file.gz, replacing it with the uncompressed file on disk, so contents are not viewed without permanent decompression. It is tempting as the standard decompression tool, and would be correct if the task were to permanently restore the original file.

  • ✓

    zcat file.gz

    Why this is correct

    zcat decompresses the gzip stream straight to standard output, writing nothing back to disk, so file.gz remains compressed. This satisfies the constraint of viewing contents without permanently decompressing, and it suits piping into grep or less.

  • ✓

    zless file.gz

    Why this is correct

    `zless` pipes the file through `gzip -d`, decompressing on the fly into a pager, so the original `file.gz` stays intact on disk. This satisfies the stem's constraint of viewing contents without permanently decompressing, since no extracted file is written and the archive remains unchanged.

About these practice questions

Courseiva writes every LFCS question from scratch — 406 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on LFCS

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A user needs to view the contents of a compressed log file /var/log/syslog.gz without first decompressing it. Which command should they use?

easy
  • ✓ A.zcat /var/log/syslog.gz
  • B.gzip -d /var/log/syslog.gz
  • C.gunzip /var/log/syslog.gz
  • D.cat /var/log/syslog.gz

Why A: `zcat` is specifically designed to read the contents of gzip-compressed files without permanently decompressing them. It decompresses the data on the fly and sends the output to stdout, allowing the user to view the log file's contents directly from the terminal.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This LFCS practice question is part of Courseiva's free Linux Foundation 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 LFCS exam.