Compressed files occupy less disk space and download faster than large, uncompressed files. You can compress Linux files with the open-source compression tool gzip and decompress the compressed files using gzip or gunzip tool. The Linux gzip tool reduces the size of the files using Lempel-Ziv coding (LZ77).
You can compress a file using gzip by the following commands. The first command will create a compressed gzip file with gz extension, removing the uncompressed file and second command will create a compressed gzip file with gz extension keeping the uncompressed file. The Linux zcat command allows the user to expand and view a compressed file without uncompressing that file.
[root@RHEL2 gzip]# gzip gzip.txt
[root@RHEL2 gzip]# gzip -c gzip.txt > gzip.txt.gz
And decompress the compressed file using the following command
[root@RHEL2 gzip]# gzip -d gzip.txt.gz
A compressed file can also decompressed by using gunzip command as shown below.
[root@RHEL2 gzip]# gunzip gzip.txt.gz
To list the compressed file information, use “gzip –l” option.
[root@RHEL2 gzip]# gzip -l gzip.txt.gz
To view a compressed file, without uncompressing it, you can use the zcat file as shown below.
[root@localhost ~]# zcat gzip.txt.gz
This is a test...