Skip to content

gzip command

Compress or decompress single files with gzip.

On this page

Syntax

gzip [options] [file…]

Provided by the gzip package. Run man gzip for the full manual.

Common options

OptionWhat it does
-dDecompress (same as gunzip)
-kKeep the original file
-rCompress files in directories recursively
-1 … -9Speed vs size (default 6)
-lShow compression ratio
-cWrite to standard output

Examples

  1. Compress a file (replaces it)

    gzip access.log
  2. Keep the original

    gzip -k dump.sql
  3. Decompress

    gunzip access.log.gz
  4. Decompress and keep the .gz

    gzip -dk file.gz
  5. Best compression

    gzip -9 data.csv
  6. Read a .gz file without extracting

    zcat access.log.gz | less
  7. Compress a database dump on the fly

    mysqldump mydb | gzip > mydb.sql.gz

gzip guides

← All Linux commands · Suggest a fix

Back to top