Skip to main content

gzip

The gzip command is used to compress files, replacing the original file with a compressed version ending in .gz. It is one of the most common compression formats in Linux.

Basic Syntax

gzip [OPTION]... [FILE]...

Common Options

OptionDescription
-d, --decompressDecompress the file (equivalent to gunzip).
-k, --keepKeep (don't delete) input files.
-r, --recursiveOperate recursively on directories.
-v, --verbosePrint name and percentage reduction for each file.
-1 to -9Regulate the speed of compression (-1 is fastest, -9 is best compression).

Real-world Examples

  1. Compress a file:

    gzip file.txt

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

  2. Compress a file and keep the original:

    gzip -k file.txt
  3. Compress with maximum compression ratio:

    gzip -9 large_file.bin
  4. Compress all files in a directory recursively:

    gzip -r /path/to/directory