GZIP(1)

GZIP(1) ๐Ÿ’–

okay bestie, welcome to the General Commands Manual entry for gzip โ€” yes that's the manual name, she lives in section 1, and she is the moment. let's get into it ๐ŸŽ€


โœจ NAME โœจ

gzip, gunzip, zcat โ€” compress or expand files ๐Ÿ—œ๏ธ๐Ÿ’ซ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

gzip [ -acdfhklLnNrtvV19 ] [-S suffix] [ name ...  ]
gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ...  ]
zcat [ -fhLV ] [ name ...  ]

like, that's the whole vibe in three lines. slay. ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so here's the tea. the gzip command shrinks the named files using Lempel-Ziv coding (LZ77). literally making your files smaller, no cap.

whenever it possibly can, each file gets replaced by one with the extension .gz โ€” and it keeps the same ownership modes, access and modification times, so nothing about your file's whole identity gets messed up. ๐Ÿ’… (btw the default extension is z for MSDOS, OS/2 FAT, Windows NT FAT and Atari. those are the little exceptions, iykyk.)

if you don't name any files, or if a file name is -, then the standard input gets compressed to the standard output. classic.

and here's a lil vibe check: gzip will only attempt to compress regular files. in particular, it will ignore symbolic links. she said "not my business, not my problem." ๐Ÿ™ˆ

๐ŸŽ€ the whole filename-too-long situation

if the compressed file name is too long for its file system, gzip truncates it. she tries to truncate only the parts of the file name longer than 3 characters โ€” and a "part" here is delimited by dots.

if the name consists of small parts only, the longest parts are truncated. for example: if file names are limited to 14 characters, then

gzip.msdos.exe

gets compressed to

gzi.msd.exe.gz

โœจ and names are not truncated on systems which do not have a limit on file name length, so if that's you, you're fine. ๐Ÿซถ

๐Ÿงš the name + timestamp thing

by default, gzip keeps the original file name and timestamp inside the compressed file. these get used when decompressing the file with the -N option. this is so useful when the compressed file name was truncated, or when the timestamp wasn't preserved after a file transfer. obsessed with a girl who plans ahead. ๐Ÿ’–

compressed files can be restored to their original form using gzip -d or gunzip or zcat. and if the original name saved in the compressed file isn't suitable for its file system, a new name gets constructed from the original one to make it valid. adaptive queen. ๐Ÿ‘‘


๐ŸŒˆ gunzip, the decompression bestie

gunzip takes a list of files on its command line and replaces each file whose name ends with .gz, -gz, .z, -z, or _z (ignoring case) and which begins with the correct magic number with an uncompressed file without the original extension.

gunzip also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively. and when compressing, gzip uses the .tgz extension if necessary instead of truncating a file with a .tar extension. she's got range, fr fr.

๐Ÿ’€ what formats can gunzip actually read

gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack. the detection of the input format is automatic โ€” no input needed from you, she just knows. โœจ

when using the first two formats, gunzip checks a 32 bit CRC. for pack and gunzip checks the uncompressed length.

now the standard compress format was not designed to allow consistency checks. however gunzip is sometimes able to detect a bad .Z file. so:

๐Ÿ˜ญ if you get an error when uncompressing a .Z file, do not assume that the .Z file is correct simply because the standard uncompress does not complain.

this generally means that the standard uncompress does not check its input, and happily generates garbage output. like ma'am. ๐Ÿšฉ

the SCO compress -H format (lzh compression method) does not include a CRC but also allows some consistency checks.

๐Ÿ“ zip files, specifically

files created by zip can be uncompressed by gzip only if they have a single member compressed with the 'deflation' method. this feature is only intended to help conversion of tar.zip files to the tar.gz format.

to extract a zip file with a single member, use a command like:

gunzip <foo.zip

or

gunzip -S .zip foo.zip

to extract zip files with several members, use unzip instead of gunzip. periodt. ๐Ÿ’…


๐Ÿ’œ zcat

the zcat command is identical to gunzip -c. (on some systems, zcat may be installed as gzcat to preserve the original link to compress.)

zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. and zcat will uncompress files that have the correct magic number whether they have a .gz suffix or not. no gatekeeping here. ๐Ÿซถ


โญ the actual compression algorithm, the science part

the gzip command uses the Lempel-Ziv algorithm used in zip and PKZIP. the amount of compression obtained depends on the size of the input and the distribution of common substrings.

typically, text such as source code or English is reduced by 60โ€“70%. ๐Ÿ”ฅ

compression is generally much better than that achieved by:

  • LZW (as used in compress)
  • Huffman coding (as used in pack)
  • adaptive Huffman coding (compact)

๐ŸŒธ the "she always compresses" disclaimer

compression is always performed, even if the compressed file is slightly larger than the original. yes bestie, sometimes it grows. it happens.

the worst case expansion is a few bytes for the gzip file header, plus 5 bytes per 32 KiB block, or an expansion ratio of 0.015% for large files.

the actual number of used disk blocks almost never increases. ๐Ÿ’–

๐ŸŽ€ permissions & timestamps

gzip normally preserves the mode and modification timestamp of a file when compressing or decompressing. and if you have appropriate privileges, it also preserves the file's owner and group. main character energy: remembers everything about you. ๐Ÿ‘‘


โœจ OPTIONS โœจ

okay bestie, this is the big one, buckle up ๐Ÿ’– every single flag, no skipping, i promise it's all useful

  • -a, --ascii โ€” ascii text mode, aka it converts end-of-lines using your local conventions ๐Ÿซถ heads up tho: this one is supported only on some non-Unix systems. on MSDOS, CR LF gets converted to LF when compressing, and LF gets converted to CR LF when decompressing. periodt.
  • -c, --stdout, --to-stdout โ€” write the output on standard output and keep the original files totally unchanged ๐Ÿ’… if you pass several input files, the output is a sequence of independently compressed members. and lowkey, if you want better compression, concatenate all the input files before compressing them.
  • -d, --decompress, --uncompress โ€” decompress. that's it, that's the whole vibe ๐Ÿฆ‹
  • -f, --force โ€” force compression or decompression even if the file has multiple links, or the corresponding file already exists, or the compressed data is being read from or written to a terminal ๐Ÿ˜ค also: if the input data is not in a format recognized by gzip, and --stdout is also given, it copies the input data without change to standard output โ€” letting zcat behave as cat. if -f is not given, and you're not running in the background, gzip prompts you to verify whether an existing file should be overwritten.
  • -h, --help โ€” display a help screen and quit โœจ
  • -k, --keep โ€” keep (don't delete) input files during compression or decompression ๐ŸŽ€
  • -l, --list โ€” for each compressed file, list these fields:
    • compressed size: size of the compressed file
    • uncompressed size: size of the uncompressed file
    • ratio: compression ratio (0.0% if unknown)
    • uncompressed_name: name of the uncompressed file

the uncompressed size is given as -1 for files not in gzip format, like compressed .Z files ๐Ÿ’€ to get the uncompressed size for such a file, you can use:

zcat file.Z | wc -c

in combination with the --verbose option, these fields are also displayed:

  • method: compression method
  • crc: the 32-bit CRC of the uncompressed data
  • date & time: timestamp for the uncompressed file

the compression methods currently supported are deflate, compress, lzh (SCO compress -H) and pack. the crc is given as ffffffff for a file not in gzip format.

with --name, the uncompressed name, date and time are those stored within the compress file if present.

with --verbose, the size totals and compression ratio for all files is also displayed, unless some sizes are unknown. with --quiet, the title and totals lines are not displayed.

  • -L, --license โ€” display the gzip license and quit ๐ŸŒธ
  • -n, --no-name โ€” when compressing, do not save the original file name and timestamp by default. (the original name is always saved if the name had to be truncated.) when decompressing, do not restore the original file name if present (remove only the gzip suffix from the compressed file name) and do not restore the original timestamp if present (copy it from the compressed file). this option is the default when decompressing ๐Ÿ‘‘
  • -N, --name โ€” when compressing, always save the original file name, and save the seconds part of the original modification timestamp if the original is a regular file and its timestamp is at least 1 (1970-01-01 00:00:01 UTC) and is less than 2**32 (2106-02-07 06:28:16 UTC, assuming leap seconds are not counted); this is the default โœจ when decompressing, restore from the saved file name and timestamp if present. this option is useful on systems which have a limit on file name length, or when the timestamp has been lost after a file transfer ๐Ÿงš
  • -q, --quiet โ€” suppress all warnings ๐Ÿคซ
  • -r, --recursive โ€” travel the directory structure recursively ๐ŸŒˆ if any of the file names specified on the command line are directories, gzip will descend into the directory and compress all the files it finds there (or decompress them in the case of gunzip).
  • -S .suf, --suffix .suf โ€” when compressing, use suffix .suf instead of .gz. although any non-empty suffix can be given so long as it does not contain "/", suffixes other than .z and .gz should be avoided to avoid confusion when files are transferred to other systems ๐Ÿ˜ญ

when decompressing, add .suf to the beginning of the list of suffixes to try, when deriving an output file name from an input file name.

  • --synchronous โ€” use synchronous output. with this option, gzip is less likely to lose data during a system crash, but it can be considerably slower ๐ŸŒ
  • -t, --test โ€” test. check the compressed file integrity then quit ๐Ÿ’ฏ
  • -v, --verbose โ€” verbose. display the name and percentage reduction for each file compressed or decompressed ๐Ÿ“Š
  • -V, --version โ€” version. display the version number and compilation options then quit โญ
  • -#, --fast, --best โ€” regulate the speed of compression using the specified digit #, where -1 or --fast indicates the fastest compression method (less compression) and -9 or --best indicates the slowest compression method (best compression) ๐Ÿ”ฅ the default compression level is -6 (that is, biased towards high compression at expense of speed).
  • --rsyncable โ€” when you synchronize a compressed file between two computers, this option allows rsync to transfer only files that were changed in the archive instead of the entire archive ๐Ÿ‘‘ normally, after a change is made to any file in the archive, the compression algorithm can generate a new version of the archive that does not match the previous version of the archive. in this case, rsync transfers the entire new version of the archive to the remote computer. with this option, rsync can transfer only the changed files as well as a small amount of metadata that is required to update the archive structure in the area that was changed.

๐ŸŒˆ ADVANCED USAGE ๐ŸŒˆ

okay so this is the part where gzip starts feeling like a main character โœจ multiple compressed files can be concatenated. in this case, gunzip will extract all members at once. for example:

gzip -c file1  > foo.gz
gzip -c file2 >> foo.gz

then

gunzip -c foo

is equivalent to

cat file1 file2

in case of damage to one member of a .gz file, other members can still be recovered (if the damaged member is removed) ๐Ÿ™ however, you can get better compression by compressing all members at once:

cat file1 file2 | gzip > foo.gz

compresses better than

gzip -c file1 file2 > foo.gz

if you want to recompress concatenated files to get better compression, do:

gzip -cd old.gz | gzip > new.gz

if a compressed file consists of several members, the uncompressed size and CRC reported by the --list option applies to the last member only ๐Ÿ’€ if you need the uncompressed size for all members, you can use:

gzip -cd file.gz | wc -c

if you wish to create a single archive file with multiple members so that members can later be extracted independently, use an archiver such as tar or zip. GNU tar supports the -z option to invoke gzip transparently ๐ŸŽ€ gzip is designed as a complement to tar, not as a replacement. no cap.


๐ŸŒธ ENVIRONMENT ๐ŸŒธ

the environment variable GZIP can hold a set of default options for gzip ๐Ÿซถ these options are interpreted first and can be overridden by explicit command line parameters. but โ€” because this can cause problems when using scripts โ€” this feature is supported only for --rsyncable, --synchronous, and options like -9 that set the compression level; any other options or operands in GZIP are silently ignored ๐Ÿ‘€

you can use an alias or script instead. for example, instead of setting GZIP="-9" in the environment, if gzip is in the directory /usr/bin you can prepend $HOME/bin to your PATH and create an executable script $HOME/bin/gzip containing the following:

#! /bin/sh
export PATH=/usr/bin
exec gzip -9 "$@"

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), pigz(1), zip(1), unzip(1), compress(1)

the gzip file format is specified in P. Deutsch, GZIP file format specification version 4.3, <https://www.ietf.org/rfc/rfc1952.txt>, Internet RFC 1952 (May 1996). the zip deflation format is specified in P. Deutsch, DEFLATE Compressed Data Format Specification version 1.3, <https://www.ietf.org/rfc/rfc1951.txt>, Internet RFC 1951 (May 1996) ๐Ÿ“š

the zlib compression library can be used to programmatically read and write gzip-format data. see <https://zlib.net>.


๐Ÿ’€ DIAGNOSTICS ๐Ÿ’€

exit status is normally 0; if an error occurs, exit status is 1. if a warning occurs, exit status is 2 โš ๏ธ

Usage: gzip [-cdfhklLnNrtvV19] [-S suffix] [file ...] : invalid options were specified on the command line ๐Ÿ™ˆ

file: not in gzip format : the file specified to gunzip has not been compressed.

file: Corrupt input. : use zcat to recover some data. the compressed file has been damaged. the data up to the point of failure can be recovered using

zcat file > recover

file: compressed with xx bits, can only handle yy bits : file was compressed (using LZW) by a program that could deal with more bits than the decompress code on this machine. recompress the file with gzip, which compresses better and uses less memory ๐Ÿง 

file: already has .gz suffix -- unchanged : the file is assumed to be already compressed. rename the file and try again.

file already exists; do you wish to overwrite (y or n)? : respond "y" if you want the output file to be replaced; "n" if not.

gunzip: corrupt input : a SIGSEGV violation was detected which usually means that the input file has been corrupted ๐Ÿ˜ญ

xx.x% Percentage of the input saved by compression. : (relevant only for -v and -l.)

-- not a regular file or directory: ignored : when the input file is not a regular file or directory, (e.g., a symbolic link, socket, FIFO, device file), it is left unaltered.

-- has xx other links: unchanged : the input file has links; it is left unchanged. see ln(1) for more information. use the -f flag to force compression of multiply-linked files ๐Ÿ’…

๐Ÿ’– CAVEATS ๐Ÿ’–

okay bestie, listen up because this one's a lil' trap ๐Ÿชค

When you're writing compressed data to a tape, it's generally necessary to pad the output with zeroes up to a block boundary. like, that's just how tapes work, no cap.

So then when the data gets read back and the whole block gets passed to gunzip for decompression, gunzip sees that there's extra trailing garbage after the compressed data and โ€” by default โ€” emits a warning ๐Ÿ˜ญ it's not broken! it's just being dramatic about the padding!

You can use the --quiet option to suppress the warning. slay ๐Ÿ’…


๐Ÿ› BUGS ๐Ÿ›

yeah she's not perfect, and we're gonna be honest about it:

  • In some rare cases, the --best option gives worse compression than the default compression level (-6). I know. the audacity ๐Ÿ’€
  • On some highly redundant files, compress compresses better than gzip. not me getting out-compressed by the old head of the group chat ๐Ÿ™ˆ

๐Ÿ“ข REPORTING BUGS ๐Ÿ“ข

found a bug? don't just scream into the void, tell the actual humans:

go forth and file that report, bestie, it's giving responsible ๐Ÿซถ


Copyright ยฉ 1998โ€“1999, 2001โ€“2002, 2012, 2015โ€“2026 Free Software Foundation, Inc. Copyright ยฉ 1992, 1993 Jean-loup Gailly

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.


and that's the whole page, bestie!! ๐ŸŽ€โœจ you made it all the way to the end, main character energy fr fr ๐Ÿ‘‘

one last lil' vibe check for the footer: this page lives in the local manual section, it's the one and only GZIP(1), and the date down there is 2026 ๐ŸŒธ so go forth, compress responsibly, and hydrate ๐Ÿ’–๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from