The gzip utility uses Lempel-Ziv (LZ77) compression techniques to reduce the size of the specified files. For each file specified, the original file is deleted and replaced with the compressed version which has the same file name as original with the file extension .gz appended. The compressed file has the same ownership modes, access time, and modification time as the original. When you do not specify any files to be compressed or specify - as a file name, gzip reads from the standard input, compresses what is read, and writes the result out to the standard output. The gzip utility will not attempt to compress special files.
To decompress files, use gzip
The gunzip utility reads each specified file and if it begins with the proper magic number and has a .gz, .z, .Z, or .bz2 extension, gunzip deletes the file and replaces it with the decompressed version of the file without the extension. In addition to the file extensions list earlier, gunzip also recognizes .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively. These two extensions are used by gzip when compressing files with a .tar extension, rather than truncating the file name (on file systems with a limited file name length).
Files compressed with the gzip utility can only be decompressed with gunzip if they contain only one member and it was compressed using the 'deflation' method. To decompress zip files with several members, use unzip instead of gunzip.
The gzcat utility behaves just like the
The Lempel-Ziv algorithm used by gzip is identical to that used by zip and PKZIP. The amount of compression obtained by this algorithm is dependent on the size of the input and the distribution of common substrings. Typically, this means that text such as source code or English is reduced by 60-70%. This results in better compression that the LZW method used by compress, the Huffman coding used by pack, or the adaptive Huffman coding used by compact.
The gzip utility always compresses the files it reads even when the resulting compressed file is larger than the input file. At worst, compressing a file with gzip only results in an increase of a few bytes the gzip file header plus 5 bytes for every 32K block, or an expansion ratio of 0.015% for large files. The actual number of disk blocks used for a file almost never increases.
uses ASCII text mode. End-of-line characters are converted using local conventions. On Windows systems, gzip converts the CR LF combination to LF when compressing file. When decompressing files, gzip
-dand gunzip convert LF back to the CR LF combination. -c --stdout --to-stdout
writes the output produced (either the compressed or decompressed file) to standard output and leaves the input files unchanged. When multiple input files are specified, each file is compressed or decompressed independently before being written to the standard output. For better compression, you should concatenate all input file before compressing or decompressing them.
-d --decompress --uncompress
decompresses the files specified on the command line.
forces compression or decompression to be performed even if the file has multiple links, the corresponding output file already exists, or if the compressed data is read from or written to a terminal. If the input files are not in a format recognized by gzip, and if the
--stdoutoption (or -cor --to-stdout) is also given, this option copies the input data unchanged to the standard output: that is, it lets gzcat behave similarly to cat.
When this option is not specified, and gzip/gunzip/gzcat is not running in the background, you are prompted to verify whether or not an existing file should be overwritten.
displays help information and quits.
displays information about each compressed file. The information is divided into the following 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
For files that were not compressed in gzip format (such as .Z files), the uncompressed size is displayed as -1. You can get the uncompressed size for such files with a command like:
gzcat file.Z | wc -c
When this option is specified in conjunction with the
--verboseor -voption, it also displays the following:
method: compression method crc: the 32-bit CRC of the uncompressed data date & time: time stamp for the uncompressed file
Currently, the only compression methods recognized and displayed are deflate, compress, lzh (SCO compress
-H) and pack. For files not compressed in gzip format, the crc field displays ffffffff.
When used with the
--nameor -Noption, this option displays the name, date, and time stored associated with the original uncompressed file if they are stored within a compressed file,
When used with the
--verboseor -voption, the -l( --list) option also displays the size totals and compression ratio for all files, unless some sizes are unknown. With the --quietor -qoption, the title and totals lines are not displayed. -L --license
displays the gzip license and quits.
when compressing files, does not save, by default, the name and time stamp for the original uncompressed file. (On file systems where the file name is truncated due to length, the name is always saved).
When decompressing, this option does not restore the name and time stamp of the original uncompressed file if the information is present. gunzip or gzip
-dsimply removes the appropriate file extension from the compressed file's name and uses that as the name for the newly decompressed file. This is the default behavior when decompressing. -N --name
when compressing files, always saves the name and time stamp for the original uncompressed file within the compressed file.
When decompressing files, this option restores the name and time stamp of the original uncompressed file.
This option is most useful on those files systems with a limit on the length of file names or when a time stamp has been lost after a file transfer. To make this behavior the default behavior, include this option in those specified by the GZIP environment variable as shown in the ENVIRONMENT VARIABLES section.
When decompressing files, you should be careful when using this option because it may create security problems. If you are running gunzip with root priveleges on a UNIX system, this option is ignored.
puts the output file in the specified output_directory.
suppresses all warnings.
works through the directory structure recursively. When one or more directories are included in the list of files specified on the the command, gzip compresses (or gunzip
specifies that the input file is not to be removed.
changes the file extension used from .gz to the specified suffix. You can use any file extension, but you probably limit yourself to either .gz or .z so that file will still be recognizable by other utilities (on Windows or other systems) that can process gzip format files .
With gunzip, when you specify an empty string as the file extension, the utility attempts to decompress all specified files regardless of their file extensions.
The .z extension is included in the recommended extensions because older versions used that as the default extension. This was later changed to avoid conflicts with pack.
tests the integrity of the compressed file.
displays additional information (the name and percentage reduction) for each file that is compressed or decompressed.
displays the version number and a list of compilation options used to build that version of the program then quit.
-# --fast --best
sets the speed at which files are compressed. The faster a file is compressed, the lower the amount of compression performed. With the
-# option, # can be a number from 1 to 9, where 1 is the fastest and 9 is the slowest. The --fastis equivalent to -1while --bestis equivalent to -9. By default, gzip performs compression as though the -6option was specified (that is, it favors a higher level of compression at the cost of speed).
There are some rare cases where the
--bestoption gives worse compression than the default compression level ( -6).
You can concatenate multiple compressed files. When you do so,
gunzip (or gzip
gzip -c file1 > catfiles.gz gzip -c file2 >> catfiles.gz
After creating the compressed file catfiles.gz, the command:
gunzip -c catfiles.gz
is equivalent to
cat file1 file2
If one of the files in such a .gz file is damaged or corrupt, the other files can still be recovered (if the damaged or corrupt member is removed).
You can improve the level of compression achieved by compressing all the files at once rather than compressing them individually and then concatenating the results. For example:
cat file1 file2 | gzip > catfiles.gz
yields better compression than:
gzip -c file1 file2 > catfiles.gz
You can recompress concatenated files to get better compression with a command like:
gzip -cd old.gz | gzip > new.gz
When a compressed file contains several individual files, the
uncompressed size and CRC reported by the
gzip -cd file.gz | wc -c
To create a single compressed file that contains individual files that you
can later extract independently, use a utility such as tar,
cpio, pax, or zip.
The tar, cpio, and
pax utilities have a
specifies the gzip options that are used by default whenever you invoke the utility. You can override these options with explicit options given on the command line. Here are some examples of how you can set this variable:
Possible exit status values are:
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
- bzdiff, bzgrep, bzip2, bzmore, compress, cpio, mkszip, pax, tar, uncompress, unpack, unzip, zcat, zip, zipinfo
MKS Toolkit Backup and Tape Handling Solutions Guide
PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.