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