gunzip, gzcat, gzip

compress or expand files 

Command


SYNOPSIS

gzip [-acdfhlLnNqrRtvV19] [-O output_directory] [-S suffix] [file ...]

gunzip [-acfhlLnNqrRtvV] [-O output_directory] [-S suffix] [file ...]

gzcat -fhRLV [-O output_directory] [file ...]


DESCRIPTION

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 -d, gunzip or gzcat. When decompressing a file on a different file system with gunzip or gzip -d, there is a possibility that the original name for the file (if stored in the compressed by using gzip -N) may not be legal on the new file system. In this case, the utility decompressing the file creates a new legal file name from the original.

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).

In addition to files compressed with gzip, gunzip can also decompress files compressed with zip, compress, compress -H, pack, or mkszip. gunzip automatically detects the compression technique used.

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 gunzip -c command. (On some systems, gzcat is installed as zcat; however, MKS Toolkit has chosen to install it as gzcat to preserve zcat as a link to uncompress.) gzcat can decompress either the files specified on the command line or, if no files are specified or - is specified as a file name, its standard input. The decompressed versions of the files read are written to the standard output. gzcat uncompresses files with the correct magic number even if they do not have .gz extension.

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.

Speedwise, gzip --fast option is roughly equivalent to that of compress.

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.

Options

-a 
--ascii 

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 -d and 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.

-f 
--force 

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 --stdout option (or -c or --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.

-h 
--help 

displays help information and quits.

-l 
--list 

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 --verbose or -v option, 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 --name or -N option, 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 --verbose or -v option, the -l (--list) option also displays the size totals and compression ratio for all files, unless some sizes are unknown. With the --quiet or -q option, the title and totals lines are not displayed.

-L 
--license 

displays the gzip license and quits.

-n 
--no-name 

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 -d simply 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.

-O output_directory 

puts the output file in the specified output_directory.

-q 
--quiet 

suppresses all warnings.

-r 
--recursive 

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

-R 

specifies that the input file is not to be removed.

-S suffix 
--suffix suffix 

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.

Note:

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.

-t 
--test 

tests the integrity of the compressed file.

-v 
--verbose 

displays additional information (the name and percentage reduction) for each file that is compressed or decompressed.

-V 
--version 

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 --fast is equivalent to -1 while --best is equivalent to -9. By default, gzip performs compression as though the -6 option was specified (that is, it favors a higher level of compression at the cost of speed).

Note:

There are some rare cases where the --best option gives worse compression than the default compression level (-6).

Compressing Multiple Files

You can concatenate multiple compressed files. When you do so, gunzip (or gzip -d) extracts all files in the compressed file as a single file. For example:

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 --list option are for the last member only. To get the uncompressed size for all members, use:

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 -z option that invokes gzip to perform compression.


ENVIRONMENT VARIABLES

GZIP 

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:

GZIP="-8v --name"; export GZIP   (for KornShell sh)
setenv GZIP "-8v --name"         (for C-Shell (csh))
set GZIP=-8v --name              (for cmd.exe)


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

1 

An error occurred.

2 

A warning occurred.


AVAILABILITY

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


SEE ALSO

Commands:
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.4 Documentation Build 39.