Search

How to compress uncompress view files using Linux commands bzip2 bunzip2 and bzcat


Compressed files occupy less disk space and download faster than large, uncompressed files. The Linux bzip2 command has better compression ratio compared with Linux gzip command.

To create a compressed file using Linux bzip2 command, use the following command. The first command will create a compressed bzip2 file with bz2 extension, removing the uncompressed file and second command will create a compressed bzip2 file with bz2 extension keeping the uncompressed file.

[root@RHEL2 bzip2]# bzip2 bzip2.txt

or

[root@RHEL2 bzip2]# bzip2 -c bzip2.txt > bzip2.txt.bz2

To decompress the bzip2 compressed file, use the “bzip2 –d” option.

[root@RHEL2 bzip2]# bzip2 -d bzip2.txt.bz2

If you want only to read the compressed file without uncompressing it, use the bzcat command as shown below.

[root@localhost ~]# bzcat bzip2.txt.bz2
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