gzip compresses files in linux and unix.
If given a file as an argument, gzip compresses the file, adds a “.gz” suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output( use “>” to redirect to a file).
Examples:Compress the file named vallu.txt. Creates vallu.gz and deletes vallu.txt.
$ gzip vallu.txt
Compress the file called vallu.txt. The standard output (which is the compressed file) is redirected by the shell to vallu.gz. Keeps vallu.txt.
$ gzip -c vallu.txt > vallu.gz
note: -c option Write compressed file to stdout and keeps the original file.
Some useful options are:
-1 Performance: Use fast compression (somewhat bigger result)
-9 Performance: Use best compression (somewhat slower)
gunzip:
gunzip uncompresses a file that was compressed with “gzip”.
Examples:Uncompress the file named vallu.gz and extracts the vallu.txt in that compressed file and deletes vallu.gz.
$ gunzip vallu.gz
Uncompress the file named vallu.gz and extracts the vallu.txt in that compressed file and keeps the vallu.gz.
$ gunzip -c vallu.gz > vallu.txt
zcat:
zcat is also same as gunzip -c it is basically used to display the content of compressed fule.
Examples:
$zcat vallu.gz