LinuxCommandLibrary

gunzip

Decompress gzipped files

TLDR

Extract a file from an archive, replacing the original file if it exists

$ gunzip [archive.tar.gz]
copy

Extract a file to a target destination
$ gunzip [[-c|--stdout]] [archive.tar.gz] > [archive.tar]
copy

Extract a file and keep the archive file
$ gunzip [[-k|--keep]] [archive.tar.gz]
copy

List the contents of a compressed file
$ gunzip [[-l|--list]] [file.txt.gz]
copy

Decompress an archive from stdin
$ cat [path/to/archive.gz] | gunzip
copy

SYNOPSIS

gunzip [options] [file...]

PARAMETERS

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

-f, --force
    Force decompression. If an output file already exists, it is overwritten. Allows decompression of files that do not have a recognized suffix.

-h, --help
    Display help message and exit.

-k, --keep
    Keep (don't delete) input files during decompression.

-L, --list
    List the contents of a compressed file. Does not decompress.

-N, --name
    When decompressing, restore the original filename and timestamp if saved in the compressed file.

-q, --quiet
    Suppress all warnings.

-r, --recursive
    Recurse into directories. If any of the file names specified on the command line are directories, gunzip will descend into the directory and decompress all files found there.

-S suffix, --suffix suffix
    Use suffix instead of .gz when searching for compressed files.

-t, --test
    Test the integrity of the compressed file. The file is decompressed in memory to check for errors, but no output file is created.

-v, --verbose
    Be verbose. Display the name and percentage reduction for each file decompressed.

-V, --version
    Display version number and exit.

DESCRIPTION

The gunzip command is used to decompress files that were compressed by the gzip utility. It is functionally equivalent to executing `gzip -d`. By default, gunzip replaces the compressed input file (typically ending with .gz, .tgz, .taz, or .Z) with its original, uncompressed version. If no files are specified, or if a file is given as -, gunzip will read from standard input and write the decompressed data to standard output, keeping the original file intact.

gunzip can decompress files created by gzip, compress (.Z), and can also handle some PKZIP archives (.zip) that contain a single entry compressed with the 'deflate' method, though for general ZIP files, unzip is recommended. It checks the integrity of the compressed file before decompressing. If an error is detected, the command will often report it and delete any partially decompressed output files to prevent corruption.

CAVEATS

By default, gunzip deletes the original compressed file after successful decompression. Use the -k option to keep the original.
It is primarily designed for single-file decompression; for complex archives like .tar.gz, it's often piped with tar (e.g., `tar -xzf file.tar.gz`).
While it can sometimes decompress single-entry PKZIP files, unzip is the dedicated tool for .zip archives.

<I>STANDARD INPUT/OUTPUT HANDLING</I>

When no file arguments are given, or if a file is specified as -, gunzip reads from standard input and writes the decompressed data to standard output. This allows it to be used in pipes, for example, `cat file.gz | gunzip` or `gunzip < file.gz > file`.

<I>EXIT STATUS</I>

gunzip exits with status 0 if processing was successful, 1 if an error occurred (e.g., malformed file, invalid arguments), and 2 if a warning occurred (e.g., file not found).

HISTORY

gunzip is part of the GNU Project's gzip package, initially developed by Jean-loup Gailly and released in 1992. It emerged as a free alternative to the proprietary compress utility, which used the LZW compression algorithm, subject to patents. gzip and consequently gunzip, quickly became the de-facto standard for lossless data compression on Unix-like systems.

SEE ALSO

gzip(1), zcat(1), uncompress(1), tar(1), zless(1), zmore(1)

Copied to clipboard