Skip to main content

gunzip

The gunzip command is used to decompress files created by gzip, zip, compress, or pack. It is functionally equivalent to gzip -d.

Basic Syntax

gunzip [OPTION]... [FILE]...

Common Options

OptionDescription
-k, --keepKeep (don't delete) input files during decompression.
-r, --recursiveOperate recursively on directories.
-c, --stdoutWrite output on standard output; keep original files unchanged.
-v, --verboseVerbose output.

Real-world Examples

  1. Decompress a .gz file:

    gunzip archive.txt.gz

    (This replaces archive.txt.gz with archive.txt)

  2. Decompress and keep the original compressed file:

    gunzip -k archive.txt.gz
  3. View the contents of a compressed file without decompressing:

    gunzip -c logfile.gz | less

    (Alternatively, use zcat logfile.gz)