How to gzip a file

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: To gzip a file, you typically use the `gzip` command in a Unix-like terminal (Linux, macOS) or a third-party compression utility on Windows. This process compresses the file, reducing its size and creating a `.gz` extension.

Key Facts

Overview

Gzipping a file is a common method for reducing its storage space and making it faster to transfer over networks. It's a form of lossless data compression, meaning no information is lost during the compression and decompression process. The most common tool used for this is the `gzip` utility, which is widely available on Unix-like operating systems.

How to Gzip a File on Linux/macOS

On Linux and macOS, the `gzip` command is the primary tool. To compress a file named my_document.txt, you would open your terminal and type:

gzip my_document.txt

This command will:

If you wish to keep the original file after compression, you can use the -k or --keep option:

gzip -k my_document.txt

This will result in both my_document.txt and my_document.txt.gz existing.

To compress multiple files at once, you can use a wildcard:

gzip *.txt

This will compress all files ending with the .txt extension in the current directory.

How to Gzip a File on Windows

Windows does not have a built-in command-line utility named `gzip` by default, but there are several ways to achieve the same result:

  1. Using File Explorer (for .zip, not .gz): While not strictly `gzip`, Windows File Explorer allows you to compress files into .zip archives. Right-click on the file(s), select "Send to," and then "Compressed (zipped) folder." This is a common alternative for general compression.
  2. Using Third-Party Software: Many free and paid applications support the GZIP format and other compression formats. Popular choices include:
    • 7-Zip: A free and open-source file archiver that supports GZIP (.gz) compression. You can download it from www.7-zip.org. After installation, you can right-click on a file, go to "7-Zip," and select "Add to archive..." choosing the desired format.
    • WinRAR: A popular commercial file archiver that also supports GZIP.
    • PeaZip: Another free file archiver with broad format support.
  3. Using Windows Subsystem for Linux (WSL): If you have WSL installed, you can access the Linux `gzip` command directly from your Windows environment.

Understanding GZIP Compression

GZIP is based on the DEFLATE compression algorithm, which is a combination of the LZ77 algorithm and Huffman coding. It's highly efficient for compressing text files, logs, and other data that contains repetitive patterns. While effective, the compression ratio can vary significantly:

The typical compression ratio for general-purpose files is often cited as being around 40-70% reduction in size.

Decompressing Gzipped Files

To decompress a file that has been gzipped, you can use the `gunzip` command or `gzip -d` on Linux/macOS:

gunzip my_document.txt.gz

or

gzip -d my_document.txt.gz

Both commands will replace my_document.txt.gz with the original my_document.txt file.

On Windows, third-party tools like 7-Zip or WinRAR can be used to extract `.gz` files. Simply right-click the `.gz` file, select the compression tool, and choose an "Extract" option.

When to Use GZIP

GZIP is particularly useful for:

It's important to note that GZIP typically compresses a single file. If you need to compress multiple files into a single archive, you would usually combine them first using a tool like `tar` (on Unix-like systems) and then gzip the resulting `.tar` file, creating a `.tar.gz` or `.tgz` archive.

Sources

  1. gzip(1) - Linux man pageCC-BY-SA-4.0
  2. Gzip - GNU Projectfair-use
  3. Gzip - WikipediaCC-BY-SA-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.