Session and utilities

The gunzip command

Decompresses .gz files back to the original, removing the compressed copy.

Syntax

gunzip [-k] archivo.gzTry it in the terminal →

Most useful options

-c, --stdoutWrites the result to the screen and leaves the original files untouched
-k, --keepKeeps the .gz on disk instead of deleting it
-f, --forceDecompresses even when the target file already exists
-t, --testChecks the integrity of the compressed file
-l, --listShows the compressed size, the original size and the compression ratio
-r, --recursiveGoes into the folders you pass and decompresses the .gz files inside
-S, --suffix SUFUses SUF instead of .gz. With -S '' it tries to decompress any file

Copy-ready examples

$ printf 'texto\n' > f.txt && gzip f.txt && gunzip f.txt.gz && lscompresses a file and decompresses it: the .gz disappears and the original stays.
$ gunzip -k informe.txt.gzdecompresses and keeps the .gz, which stays on disk.
$ printf 'texto\n' > f.txt && gzip -k f.txt && gunzip -c f.txt.gzreads the content of the .gz on screen and leaves the file as it was.

Example output

texto
$ gunzip -l informe.txt.gzcompressed size, original size and compression ratio, without decompressing anything.
$ gunzip -S .x archivo.xdecompresses a file with another suffix; the result is called archivo, with no extension.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
gzip: falso.gz: not in gzip formatThe file is not in gzip format: it was not compressed, the download was incomplete or it carries another format's extension.Check what it contains with file falso.gz. If it is a .zip with several files, use unzip.
gzip: nada.gz: No such file or directoryThe name or the path does not match any file.List the folder with ls and copy the exact name.
gzip: plano.txt: unknown suffix -- ignoredgunzip only processes names with a compression suffix, such as .gz. It ignores the rest with this warning.If the file is gzip, rename it with .gz. If it has another suffix, pass it with -S.

Typical mistakes

  • Without -k, gunzip deletes the .gz when it finishes. If you need it later, decompress with -k.
  • If the target file already exists, gunzip does not overwrite it without -f: it fails or asks for confirmation.
  • gunzip does not understand .bz2 or .xz: those formats need their own tools.
  • A .zip with several files cannot be extracted with gunzip: for those, use unzip.

Differences from similar commands

  • gzip -d: does the same as gunzip. They are two ways of calling the same decompression mode.
  • zcat: is identical to gunzip -c: it writes the content to the screen and leaves the file alone.
  • unzip: opens .zip files, including those with several files, which gunzip cannot extract.

Related commands

FAQ

Can I decompress several files at once?

Yes: gunzip takes a list. With -r it also goes into the folders you pass and decompresses the .gz files they contain.

What do I do with a .tar.gz or a .tgz?

gunzip turns a .tar.gz into a .tar, which is still packed. It recognises a .tgz as a .tar.gz. To get the files out, unpack the .tar with tar.

Does gunzip restore the original file name?

Not by default: it only removes the .gz suffix. To restore the name and timestamp saved inside the file, use -N.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course