Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use gzip filename to compress a file into a .gz file, usually removing the original. Use gzip -d filename.gz or gunzip filename.gz to decompress it. To keep the original, add -k. For a group of files or a directory, create a tar archive and compress it with tar -czf.

Compress and decompress a file

GNU gzip normally replaces a regular input file with a compressed file whose name ends in .gz. For example:

gzip report.txt

This produces report.txt.gz and removes report.txt. The gzip stream stores the original name and timestamp by default where supported, which can help restore the filename and time during decompression.

To restore the file, run either command:

gzip -d report.txt.gz
# Equivalent command name
gunzip report.txt.gz

By default, decompression removes the compressed input after creating the uncompressed file. Use -k when you want to retain the input during either operation:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
gzip -k report.txt
gzip -dk report.txt.gz

The first command leaves both report.txt and report.txt.gz; the second decompresses the stream while retaining report.txt.gz.

Keep the original or send compressed data to a file

There are two useful ways to keep the source file. The simplest is -k. Alternatively, -c writes compressed bytes to standard output, so shell redirection can create the destination without replacing the input:

gzip -c report.txt > report.txt.gz

Here, the shell creates or replaces report.txt.gz, while gzip reads report.txt and leaves it in place. Avoid choosing a redirection destination that is the same path as the input: the shell may truncate that file before gzip reads it.

You can also pipe standard input into gzip:

cat report.txt | gzip > report.txt.gz

When gzip -c receives multiple files, its output is a sequence of independently compressed gzip members, not a tar-style archive with a directory of named entries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a compression level

GNU gzip offers levels -1 through -9. Level -1 prioritizes speed and generally compresses less; -9 spends more time seeking stronger compression. The default is -6. The actual time and size depend on the input, so a higher level is not automatically worthwhile for every file.

The GNU Gzip 1.14 manual, dated 24 February 2025, says text such as source code or English is typically reduced by 60–70%. That is a qualified typical range, not a promise for a particular file. Some files shrink little or not at all: GNU gzip still compresses them, and its documented worst case is a few bytes for the gzip header plus five bytes per 32 KiB block.

Understand the difference between .gz and .tar.gz

A .gz file is a compressed stream. gzip does not group a directory’s contents into a conventional multi-file archive. To package several files or a directory as one archive and then compress it, use tar with gzip integration:

tar -czf project.tar.gz project/

In .tar.gz, tar groups the files into a tar archive, and gzip compresses that archive stream. To extract it:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
tar -xzf project.tar.gz

GNU’s manual puts the distinction succinctly: “gzip is designed as a complement to tar, not as a replacement.” Use a standalone .gz for a single file; use .tar.gz when you need archive-level grouping and extraction for multiple files.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Useful gzip options

Option What it does When to use it
-c, --stdout Writes compressed or decompressed data to standard output. Redirect or pipe the output while leaving the input file unchanged.
-d, --decompress Decompresses a gzip stream. Restore the contents of a .gz file.
-k, --keep Keeps input files during compression or decompression. Retain the source or compressed copy.
-r, --recursive Recursively processes files in directories in GNU gzip. Apply gzip to eligible files in a directory tree; it does not create a multi-file archive.
-t, --test Checks the integrity of compressed files. Check a gzip file without extracting it.
-l, --list Lists compressed size, uncompressed size, ratio, and uncompressed name. Inspect a gzip file’s listing information.
-1 through -9 Sets the speed-versus-compression trade-off; default is -6. Choose a faster or more compression-focused pass.
-n and -N Control whether original name and time metadata are saved or restored. Adjust metadata handling when the default behavior is not wanted.
-f, --force Forces operations in cases such as an existing output or linked files. Only when you understand possible overwrites and the effect on linked files.

GNU gzip normally ignores symbolic links rather than compressing their targets. Be particularly careful with -f, which can force overwriting or permit compression of linked files.

Test a gzip file and inspect its listing

Run these commands to check a stream and view its reported information:

gzip -t report.txt.gz
gzip -l report.txt.gz

A successful -t check produces no error message. The listing reports sizes, ratio, and uncompressed name. Gzip streams can contain concatenated members; for such a stream, GNU gzip’s listed uncompressed size and CRC apply only to the last member, so the listing is not a complete per-member inventory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check which gzip implementation is installed

The option descriptions and behaviors above are based on the GNU Gzip 1.14 manual (24 February 2025). Linux distributions can package other versions or implementations, so check the local command before relying on version-specific behavior:

gzip --version
gzip --help

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.