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.Zfile, do not assume that the.Zfile is correct simply because the standarduncompressdoes 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 LFgets converted toLFwhen compressing, andLFgets converted toCR LFwhen 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 bygzip, and--stdoutis also given, it copies the input data without change to standard output โ lettingzcatbehave ascat. if-fis not given, and you're not running in the background,gzipprompts 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 fileuncompressed size: size of the uncompressed fileratio: 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 methodcrc: the 32-bit CRC of the uncompressed datadate & 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 thegziplicense 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 least1(1970-01-01 00:00:01 UTC) and is less than2**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,gzipwill descend into the directory and compress all the files it finds there (or decompress them in the case ofgunzip).-S .suf,--suffix .sufโ when compressing, use suffix.sufinstead of.gz. although any non-empty suffix can be given so long as it does not contain"/", suffixes other than.zand.gzshould 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,gzipis 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-1or--fastindicates the fastest compression method (less compression) and-9or--bestindicates 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 allowsrsyncto 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,rsynctransfers the entire new version of the archive to the remote computer. with this option,rsynccan 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
--bestoption gives worse compression than the default compression level (-6). I know. the audacity ๐ - On some highly redundant files,
compresscompresses better thangzip. 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:
- Report bugs to:
bug-gzip@gnu.org - GNU gzip home page: <https://www.gnu.org/software/gzip/>
- General help using GNU software: <https://www.gnu.org/gethelp/>
go forth and file that report, bestie, it's giving responsible ๐ซถ
ยฉ๏ธ COPYRIGHT NOTICE ยฉ๏ธ
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
- arch rolling: gzip 1.15-1 ยท GPL-3.0-or-later
- nixpkgs unstable: gzip 1.15
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms