In this article we will learn how to compress and decompress file in linux . Before that first we have to know what is file compression and why we need to compress a fIle . Compression is method in which the logical size of the file is reduced . There are many advantages of file compression. Through file compression we can save our disk space and it is very easy to send that file over network.

Decompression is used to restore our file data to its original form. There are many tools available to compress and decompress a file in linux . But as per our discussion we disscuss about bzip2 tools in this article . bzip2 is very popular compression tool in linux distribution .

Installation of bzip2 tools

It is installed by default . If it is not installed in your system , you can install it with the help of command given below –

The output of this command is looks like –

compress and decompress file in linux
After installation you can compress and decompress file in linux system

Compress a file using Bzip2

To compress a file using bzip2 , you can use command given below –

The output of this command –

bzip2
During this opertaion , the original file is deleted automatically . To keep your original file use -k (–keep) flag .

bzip2
Decompress a file using bzip2

To decompress a file using bzip2 , you can use command given below –

The output of this command looks like –

bzip2
-d flag is used to decompress a compressed file . -k flag is used to keep the original file . If we will not use -k flag , the original compressed file will be deleted .

bzip2

You may also like to read following article :

In this short article , we have explained about how to compress an d decompress .bzip2 file in linux.  Please subscribe to newsletter for updated articles. We will discuss about many other topics in next articles.