You get a bonus - 1 coin for daily activity. Now you have 1 coin

Working with bz2 or tar.bz2 Archives

Practice



A short note on how to work with bz2 (bzip2) archives.


Installation

1) First, we'll need the bzip2 utility.

On CentOS/RedHat it's most likely already installed. If not, install it:

$ sudo yum install bzip2

Debian/Ubuntu:

Install it:

$ sudo aptitude install bzip2

FreeBSD:

Just like on CentOS, it should be there out of the box. If not, install it:

$ cd /usr/ports/archivers/bzip2
$ sudo make install clean


Usage

1) Unpacking a bz2 archive

$ bunzip2 myarchive.bz2

or

$ bzip2 -d myarchive.bz2


2) Packing a bz2 archive

$ bzip2 myfile1 myfile2 myfile3

This creates a separate bz2 archive for each specified file, named:
file name + .bz2

in this example: myfile1.bz2, myfile2.bz2, myfile3.bz2


3) Packing a bz2 archive with a specified compression level

Fast method:
$ bzip2 -1 myfile1

High-quality method (best compression):
$ bzip2 -9 myfile2


Multiple files into a single archive, or tar.bz2

The bzip2 utility works with each file separately, packing each file on its own. If you feed it several files, it will just create a separate archive for each one.

To put several files into a single archive, you use the tar utility.

That is, we first need to gather all the files into a single tar archive, and only then compress that archive. The thing is, tar itself can't compress anything — it just packs a bunch of files into one archive.


1) Creating a tar.bz2 archive

$ tar -cf myfile.tar myfile1 myfile2 myfile3
$ bzip2 myfile.tar

The result is myfile.tar.bz2

Here we first create a tar archive named myfile.tar, into which we include the files myfile1, myfile2, and myfile3; after that we compress this archive (myfile.tar) using bzip2 into myfile.tar.bz2


2) Unpacking tar.bz2

$ bunzip2 myfile.tar.bz2
$ tar -xf myfile.tar

Here, using the bzip2 (bunzip2) utility, we first decompress the myfile.tar.bz2 archive, getting a single myfile.tar file; then we extract myfile.tar into the individual files.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system