Home·Terminal commands

gunzip

Archives

Usage

gunzip [-k] <file.gz>

Unpacks a .gz back to the original file and removes the .gz on success, so `-k` keeps it, `-f` is needed when a file of that name already exists, and `-c` streams the contents out without ever writing them to disk, exactly like zcat.

Common flags

FlagMeaning
-kKeep the .gz file instead of removing it on success.
-cWrite to stdout and touch nothing on disk, the same as zcat.
-fOverwrite an existing output file, which it otherwise refuses to do.
-tTest the file instead of unpacking it.
-lList the sizes inside.

Examples

gunzip backup.sql.gz

Leaves backup.sql; the .gz file is removed.

gunzip -c dump.sql.gz | psql mydb

Restore without ever writing the uncompressed file to disk.

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 gunzip do?

Unpacks a .gz back to the original file and removes the .gz on success, so `-k` keeps it, `-f` is needed when a file of that name already exists, and `-c` streams the contents out without ever writing them to disk, exactly like zcat.

Q. How do I type it?

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

Q. How many flags are worth knowing?

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

Related commands

man page: man gunzip