Linux "gzip" Command Line Options and Examples
compress or expand files

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


Usage:

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






Command Line Options:

-a
Ascii text mode: convert end-of-lines using local conventions. This option is supported only on some non-Unix systems. ForMSDOS, CR LF is converted to LF when compressing, and LF is converted to CR LF when decompressing.
gzip -a ...
-c
Write output on standard output; keep original files unchanged. If there are several input files, the output consists of asequence of independently compressed members. To obtain better compression, concatenate all input files before compressingthem.
gzip -c ...
-f
Force compression or decompression even if the file has multiple links or the corresponding file already exists, or if thecompressed data is read from or written to a terminal. If the input data is not in a format recognized by gzip, and if theoption --stdout is also given, copy the input data without change to the standard output: let zcat behave as cat. If -f isnot given, and when not running in the background, gzip prompts to verify whether an existing file should be overwritten.
gzip -f ...
-h
Display a help screen and quit.
gzip -h ...
-k
Keep (don't delete) input files during compression or decompression.
gzip -k ...
-l
For each compressed file, list the following 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 fileThe uncompressed size is given as -1 for files not in gzip format, such as compressed .Z files. To get the uncompressed sizefor such a file, you can use:zcat file.Z | wc -cIn combination with the --verbose option, the following fields are also displayed:method: compression methodcrc: the 32-bit CRC of the uncompressed datadate & time: time stamp for the uncompressed fileThe compression methods currently supported are deflate, compress, lzh (SCO compress -H) and pack. The crc is given asffffffff 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
gzip -l ...
--quiet
the title and totals lines are not displayed.
gzip --quiet ...
-L
Display the gzip license and quit.
gzip -L ...
-n
When compressing, do not save the original file name and time stamp by default. (The original name is always saved if the namehad to be truncated.) When decompressing, do not restore the original file name if present (remove only the gzip suffix fromthe compressed file name) and do not restore the original time stamp if present (copy it from the compressed file). Thisoption is the default when decompressing.
gzip -n ...
-N
When compressing, always save the original file name and time stamp; this is the default. When decompressing, restore theoriginal file name and time stamp if present. This option is useful on systems which have a limit on file name length or whenthe time stamp has been lost after a file transfer.
gzip -N ...
-q
Suppress all warnings.
gzip -q ...
-r
Travel the directory structure recursively. If any of the file names specified on the command line are directories, gzip willdescend into the directory and compress all the files it finds there (or decompress them in the case of gunzip ).
gzip -r ...
--rsyncable
While compressing, synchronize the output occasionally based on the input. This increases size by less than 1 percent mostcases, but means that the rsync(1) program can take advantage of similarities in the uncompressed input when synchronizing twofiles compressed with this flag. gunzip cannot tell the difference between a compressed file created with this option, andone created without it.
gzip --rsyncable ...
-S
When compressing, use suffix .suf instead of .gz. Any non-empty suffix can be given, but suffixes other than .z and .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 inputfile name.
gzip -S ...
-t
Test. Check the compressed file integrity.
gzip -t ...
-v
Verbose. Display the name and percentage reduction for each file compressed or decompressed.
gzip -v ...
-V
Version. Display the version number and compilation options then quit.
gzip -V ...
-#
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 compressionlevel is -6 (that is, biased towards high compression at expense of speed).ADVANCED USAGEMultiple compressed files can be concatenated. In this case, gunzip will extract all members at once. For example:gzip -c file1 > foo.gzgzip -c file2 >> foo.gzThengunzip -c foois equivalent tocat file1 file2In case of damage to one member of a .gz file, other members can still be recovered (if the damaged member is removed). However, youcan get better compression by compressing all members at once:cat file1 file2 | gzip > foo.gzcompresses better thangzip -c file1 file2 > foo.gzIf you want to recompress concatenated files to get better compression, do:gzip -cd old.gz | gzip > new.gzIf a compressed file consists of several members, the uncompressed size and CRC reported by the --list option applies to the lastmember only. If you need the uncompressed size for all members, you can use:gzip -cd file.gz | wc -cIf you wish to create a single archive file with multiple members so that members can later be extracted independently, use anarchiver 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.ENVIRONMENTThe environment variable GZIP can hold a set of default options for gzip. These options are interpreted first and can be overwrittenby explicit command line parameters. For example:for sh: GZIP="-8v --name"; export GZIPfor csh: setenv GZIP "-8v --name"for MSDOS: set GZIP=-8v --nameOn Vax/VMS, the name of the environment variable is GZIP_OPT, to avoid a conflict with the symbol set for invocation of the program.
gzip -# ...