Home·Terminal commands

gzip

Archives

Usage

gzip [-k] <file>

Compresses a single file into .gz and, by default, deletes the original once it succeeds, so keep it with `-k` or by writing to stdout with `-c`; it never bundles several files, which is why tar comes first.

Common flags

FlagMeaning
-kKeep the original. Without it, gzip deletes the file it just compressed.
-dDecompress, which is exactly what gunzip does.
-cWrite to stdout and leave the input alone.
-1 / -9Fastest / smallest. The default is -6.
-lShow the compressed and original sizes of a .gz file.
-tTest the integrity without unpacking.
-rWalk a directory and compress each file separately.

Examples

gzip -9 access.log

Creates access.log.gz. The original access.log is gone.

gzip -c report.csv > report.csv.gz

Compress while keeping the original.

gzip -l backup.sql.gz

How much it actually saved.

Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does gzip do?

Compresses a single file into .gz and, by default, deletes the original once it succeeds, so keep it with `-k` or by writing to stdout with `-c`; it never bundles several files, which is why tar comes first.

Q. How do I type it?

gzip [-k] <file> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man gzip. This command sits under Archives.

Related commands

man page: man gzip