Search

How to compress, uncompress and view files using Linux commands gzip, gunzip and zcat

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

gzip/gunzip/zcat

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

Or

[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...
1
2
3
4
5
6
7
8
9
10

Related Tutorials
• How to compress, uncompress and view files using Linux commands gzip, gunzip and zcat
• How to use Linux tar (tape archive) command to create archives
• Introduction to RedHat Package Manager (RPM)
• Introduction to YUM (Yellow dog Updater, Modified) Package Manager