- Unix Commands Reference
- Unix - Tutorial Home
gzip - Unix, Linux Command
gunzip, gzip - compress or expand files
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ] gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
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. (The default extension is -gz for VMS, z for MSDOS, OS/2 FAT, Windows NT FAT and Atari.) If no files are specified, or if a file name is "-", the standard input is compressed to the standard output. Gzip will only attempt to compress regular files. In particular, it will ignore symbolic links.
If the compressed file name is too long for its file system, gzip truncates it. Gzipattempts to truncate only the parts of the file name longer than 3 characters. (A part 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, gzip.msdos.exe is compressed to gzi.msd.exe.gz. Names are not truncated on systems which do not have a limit on file name length.
By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -N option. This is useful when the compressed file name was truncated or when the time stamp was not preserved after a file transfer.
Compressed files can be restored to their original form using gzip -d or gunzip or zcat. If the original name saved in the compressed file is not suitable for its file system, a new name is constructed from the original one to make it legal.
|ASCII text mode: convert end-of-lines using local conventions. This option is supported only on some non-Unix systems. For MSDOS, CR LF is converted to LF when compressing, and LF is converted to CR LF when decompressing.
|-c, --stdout, --to-stdout
|Write output on standard output; keep original files unchanged. If there are several input files, the output consists of a sequence of independently compressed members. To obtain better compression, concatenate all input files before compressing them.
|-d, --decompress, --uncompress
|Force compression or decompression even if the file has multiple links or the corresponding file already exists, or if the compressed data is read from or written to a terminal. If the input data is not in a format recognized by gzip, and if the option --stdout is also given, copy the input data without change to the standard output: let zcat behave as cat. If -f is not given, and when not running in the background, gzip prompts to verify whether an existing file should be overwritten.
|Display a help screen and quit.
|Display the gzip license and exit.
|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 time stamp if present (copy it from the compressed file). This option is the default when decompressing.
|When compressing, always save the original file name and time stamp; this is the default. When decompressing, restore the original file name and time stamp if present. This option is useful on systems which have a limit on file name length or when the time stamp has been lost after a file transfer.
|Suppress all warnings.
|Travel the directory structure recursively. If any of the file names specified on the command line are directories, gzip will descend into the directory and compress all the files it finds there (or decompress them in the case of gunzip).
|-S .suf, --suffix .suf
|When compressing, use suffix .suf instead of .gz. Any non-empty suffix can be given, but suffixes other than .z and .gz should 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.
|Test. Check the compressed file integrity.
|Verbose. Display the name and percentage reduction for each file compressed or decompressed.
|Version. Display the version number and compilation options then quit.
|-#, --fast, --best
|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 compression level is -6 (that is, biased towards high compression at expense of speed).
To Compress A File Using "gzip":
$ gzip test.sh
$ gzip test.sh
To Decompress A File Using The "gzip" Command:
$ gzip -d test.sh.gz
$ gzip -d test.sh.gz
Force A File To Be Compressed:
$ gzip -f filenatest.sh
$ gzip -f test.sh
To Keep The Uncompressed File:
$ gzip -k filename
$ gzip -k test.sh
Compress Every File In A Folder And Subfolders:
$ gzip -r /tmp
$ ls /tmp/
$ gzip -r /tmp/
$ ls /tmp/
To Test The Validity Of A Compressed File:
$ gzip -t test.sh.gz
no output on screen if compressed file is valid.
To Change The Compression Level:
To get minimum compression at the fastest speed:
$ gzip -1 test.sh
To get maximum compression at the slowest speed:
$ gzip -9 test.sh