- [Instructor] Let's now move on to the fifth video
of this section, Faster Archiving with pbzip2.
In the previous video, we looked at archiving
and compressing with the zip command.
In this video, we'll use the pbzip2 command
to perform faster archiving.
We'll first compress a single file,
extract a pbzip2 file, and then we'll be exploring
about manually specifying the number of CPUs.
Most modern computers today are equipped
with at least two CPU cores.
For the user, it means almost the same
as two real CPUs doing the work.
However, just having a multicore CPU
doesn't mean your programs will run faster.
It's important that the programs themselves
have been designed to run faster on multicore processors.
Most of the compression commands that we've seen up till now
will use only one CPU and, hence, won't be very fast.
pbzip2 can use multiple cores,
hence decreasing overall time taken to compress your files.
So let's now get ready for our task.
pbzip2 usually doesn't come pre-installed with most distros.
You'll have to use your package manager to install it.
Let's see how to use pbzip2
to compress files and extract them.
So we compress a single file in this way.
pbzip2 will automatically detect the number of cores
in your system and compress myfile.tar to myfile.tar.bz2.
Now, to compress and archive multiple files or directories,
we use pbzip2 in conjunction with tar, as we did here.
You could also use this command,
which is an alternate method.
Let's now look into how to extract a pbzip2'd file.
If it's a tar.bz2 file,
we can perform the decompression and extraction
in one step, as we do here.
Now, if the archive is a single file,
which was pbzip2'd, use this command.
Let's understand how it works.
pbzip2 internally uses the same
compression algorithms as bzip2,
but it compresses separate chunks of data simultaneously
using pthreads, a threading library.
However, this is all transparent to the user,
and all that happens is a much faster compression.
Just like gzip or bzip2,
pbzip2 does not create archives itself,
it can only work on a single file.
Hence, to compress multiple files and directories,
we use it in conjunction with tar.
There are other useful options we can use with pbzip2.
Let's now talk again about some additional information.
Here, we talk about manually specifying the number of CPUs.
So you can use the minus p option to pbzip2
to specify the number of CPU cores manually.
This is useful if the automatic detection fails
or you want some CPU cores to be free for some other job.
This will tell pbzip2 to use four CPUs.
Finally, let's talk about specifying the compression ratio.
Just like other compression tools we saw up to now,
we can use the options from one to nine
to specify the fastest
and best compression ratios, respectively.
Cool, in this video, we've learned how to compress
and extract files with pbzip2 command
and manually specify the number of CPUs.
In the next video,
we'll learn about creating filesystems with compression.