bzip2 utility - how to compress and decompress files in Linux

bzip2 utility - how to compress and decompress files in Linux

Colleagues hello to all.

In today's article, we will talk about how you can compress and decompress files in Linux using the bzip2 utility. Compressing files with the bzip2 utility means reducing the size of files by encoding data in files using fewer bits.

 

First you need to install the bzip2 utility. If you do not have the utility installed, then you can install it through the yum package manager.

$. yum install bzip2

linux_bzip2

I already had the bzip2 utility installed earlier.


 

The easiest way to compress a file is to run the bzip2 command and specify the file we want to compress. In all examples, we will experiment with the test.sql file.

$. bzip2 test.sql

or

$. bzip2 -z test.sql

linux_bzip2

As you can see from the example, the size of the test.sql file before compression was 100 megabytes, and after executing the compression command it became 17 megabytes.

 

There is a very important point about using bzip2. By default, bzip2 deletes input files during compression or decompression. If you want all input files to be untouched, then you need to use the command with additional options such as -k or --keep.

$. bzip2 -k test.sql

or

$. bzip2 --keep test.sql

linux_bzip2

As you can see from the example, the test.sql file remained untouched, while the test.sql.bz2 file was created in a compressed form.


 

In order to unpack ".bz2" files you need to run the bzip2 command with additional options like -d or --decompress.

$. bzip2 -d test.sql.bz2

or

$. bzip2 --decompress test.sql.bz2

linux_bzip2

As you can see from the example, after executing the command, the test.sql.bz2 file disappeared, and the test.sql file appeared in its original size.


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

tar utility - how to zip and unzip files in linux
tar utility - how to zip and unzip files in linux
LINUX
Read more
How to find out the size of a file and directory in Linux
How to find out the size of a file and directory in Linux
LINUX
Read more
lsof utility - find out what ports are listening in Linux
lsof utility - find out what ports are listening in Linux
LINUX
Read more