Compress or expand files (UNIX)
Compress/uncompress files:
gzip [-cdfhLlNnqrtVv19] [-S suffix] [name...]
Uncompress only:
gunzip [-cfhLlNnqrtvV] [name...]
Cat compressed file:
zcat [-hLV] [name...]
The gzip utility reduces the size of the named files, using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. (The extension is -z for VMS, z for MSDOS, OS/2 and Atari.) If no files are specified, the standard input is compressed to the standard output. If the new file name is too long, gzip truncates it and keeps the original file name in the compressed file. The gzip utility attempts to compress only regular files. In particular, it ignores symbolic links.
You can use gzip -d, gunzip, or zcat to restore compressed files to their original form.
The gunzip utility takes a list of files on its command line and replaces each file whose name ends with .gz or .GZ or -z and which begins with the correct magic number with an uncompressed file without the original extension. This utility also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz or .tar.GZ.
The gunzip utility can currently decompress files created by gzip, zip, compress or pack. The detection of the input format is automatic. When using the first two formats, gunzip checks a 32-bit CRC. For pack, gunzip checks the uncompressed length. The compress format wasn't designed to allow consistency checks. However gunzip is sometimes able to detect a bad .GZ file. If you get an error when uncompressing a .GZ file, don't assume that the .GZ file is correct just because the standard uncompress doesn't complain. This generally means that the standard uncompress doesn't check its input, and happily generates garbage output.
You can use gzip to uncompress files created by zip only if they have a single member compressed with the "deflation" method. This feature is intended only to help conversion of tar.zip files to the tar.gz format. To extract zip files with several members, obtain and use unzip instead of gunzip. (Note that unzip isn't shipped as part of QNX Neutrino.)
The zcat utility is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) The zcat utility uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. It uncompresses files that have the correct magic number whether they have a .gz suffix or not.
The gzip utility 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), or adaptive Huffman coding (compact).
Compression is always performed, even if the compressed file is slightly larger than the original. The worst case expansion is a few bytes for the gzip file header, plus 5 bytes every 32K block, or an expansion ratio of 0.015% for large files. The gzip utility preserves the mode, ownership and timestamps of files when compressing or decompressing.
You can concatenate multiple compressed files. In this case, gunzip extracts 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:
zcat old.gz | gzip > new.gz
export GZIP="-8 -v"
GNU
The .gz extension is already also used by UNIX pack. You can link gzip to pcat to get transparent decompression for programs expecting .gz files to be in pack format.
Backing Up and Recovering Data in the Neutrino User's Guide