O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Compressing with bunzip (bzip)

bunzip2 is another compression technique which is very similar to gzip. bzip2 typically produces smaller (more compressed) files than gzip. It comes with all Linux distributions. Let's see how to use bzip2.

How to do it...

In order to compress with bzip2 use:

$ bzip2 filename
$ ls
filename.bz2

Then it will remove the file and produce a compressed file called filename.bzip2.

Extract a bzipped file as follows:

$ bunzip2 filename.bz2

It will remove filename.bz2 and produce an uncompressed version of filename.

bzip2 can read a file from stdin and also write a compressed file into stdout.

In order to read from stdin and read out as stdout use:

$ cat file | bzip2 -c > file.tar.bz2

-c is used to specify output to stdout

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required