LinuxCommandLibrary

gzip

Compress files to reduce their size

TLDR

Compress a file, replacing it with a gzip archive

$ gzip [path/to/file]
copy

Decompress a file, replacing it with the original uncompressed version
$ gzip [[-d|--decompress]] [path/to/file.gz]
copy

Compress a file, keeping the original file
$ gzip [[-k|--keep]] [path/to/file]
copy

Compress a file, specifying the output filename
$ gzip [[-c|--stdout]] [path/to/file] > [path/to/compressed_file.gz]
copy

Decompress a gzip archive specifying the output filename
$ gzip [[-c|--stdout]] [[-d|--decompress]] [path/to/file.gz] > [path/to/uncompressed_file]
copy

Specify the compression level. 1 is the fastest (low compression), 9 is the slowest (high compression), 6 is the default
$ gzip -[1..9] [[-c|--stdout]] [path/to/file] > [path/to/compressed_file.gz]
copy

Display the name and reduction percentage for each file compressed or decompressed
$ gzip [[-v|--verbose]] [[-d|--decompress]] [path/to/file.gz]
copy

SYNOPSIS

gzip [options] [file...]

PARAMETERS

-d or --decompress or --uncompress
    Decompress the specified files.

-c or --stdout or --to-stdout
    Write output on standard output; keep original files unchanged.

-f or --force
    Force compression or decompression even if the file has multiple links or if a file already exists.

-h or --help
    Display a help screen and exit.

-l or --list
    List compressed file contents.

-n or --no-name
    When compressing, do not save the original file name and timestamp.

-N or --name
    When compressing, save the original file name and timestamp (default).

-q or --quiet
    Suppress all warnings.

-r or --recursive
    Operate recursively on directories.

-t or --test
    Test compressed file integrity.

-v or --verbose
    Print verbose output.

-1 or --fast
    Use the fastest compression method (least compression).

-9 or --best
    Use the best compression method (slowest compression).

--rsyncable
    Compress so that rsync can delta-transfer the compressed file if the original file has changed.

DESCRIPTION

gzip is a command-line utility used for compressing and decompressing files. It reduces the size of files using the Lempel-Ziv coding (LZ77).

When compressing, gzip typically replaces the original file with a file ending in '.gz'. The original file can be recreated using gzip -d or gunzip. gzip attempts to compress the whole file at once. The amount of compression depends on the size of the input file and distribution of common substrings.

A compressed file contains, besides the compressed data, the name and timestamp of the original file, recovery of disk space usage and consistency check.

CAVEATS

gzip compresses individual files and doesn't archive them. For archiving and compression, use tar combined with gzip (e.g., tar -czvf archive.tar.gz directory).

EXIT STATUS

The exit status is normally 0. If an error occurs, the exit status is 1 or greater.

ENVIRONMENT

The environment variable GZIP can be used to set default options for gzip. For example: GZIP="-9vr" sets the compression level to the best, enables verbose mode, and operates recursively on directories.

HISTORY

gzip was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program, which was patented. The first version was released on October 31, 1992.
It quickly became the standard compression tool on Unix-like systems due to its efficiency and open-source nature.

SEE ALSO

gunzip(1), zcat(1), tar(1), bzip2(1), xz(1)

Copied to clipboard