- In this video
we are going to talk about compression utilities.
There's a couple of compression utilities
that are commonly used in a Linux environment.
To start with, there is gzip.
If you want to use gzip in tar, you use the Z option.
This is the most common compression utility
because it's giving a nice balance between compression ratio
and time that it takes to create the archive.
There is bzip2 or -J, if you use it in tar,
that's an alternative utility
which is offering better compression, but it takes longer.
And there is xzip,
or -J uppercase J in tar is a utility relatively
new that offers the best possible compression
but is significantly slower.
And also for those of you who know it
from other environments, there is zip utility
and the zip utility has a windows compatible syntax.
The zip utility mainly is something from history.
You don't really need it nowadays anymore.
And that is because windows nowadays also
reads Linux native compression formats like gzip.
If you have a gzip file
you can easily read that on windows as well.
Now, the main difference
between these compression utilities is the ratio
and time it takes to compress
and you can use time to measure the time that it takes.
And well, let me show you how to use it.
So to start with, I want to get back to this
this first tar command that we have used.
I'm going to modify it a little bit.
First thing that I'm going to modify
I am going to compress.
So I want to that to be easily seen from the
the extensions, you can go to waste for the extension.
I'm using .tar.z, which is totally acceptable.
You could also use .dgz as the extension
which would also work.
The next thing that we need to change is the
compression option and this compression option that is the Z
that I'm going to add.
And then the final thing that I wanna do
I want to put the time command in front of it,
because there are two things that really
matter regarding compression
and that is the compression ratio
but also the time that it takes.
So let's record the time so
that we can actually see how much time it is taking.
There we go.
As you can see, there was a reasonable eight seconds.
Okay. That was take one.
Let's do take two.
And then take two.
We are creating bz a bz2 compressed file.
The extension here really doesn't matter
because it's just to inform your users.
So use any extension that you want.
I am going to use J, J entire is the option for bz
to compression and for the rest of it
we don't need to change anything.
I want to create an archive of exactly the same.
And again, we are going to record the time.
We have just seen eight seconds in total.
So I'm wondering how much time is this going to take?
And as you can see more than double, 22 seconds in total.
All right, of course you wanna know
about Contra compression ratio as well.
We are going to find out in just a little bit
but first I want to do my third run, the xz utility.
So again, I'm changing the extension
and we are using uppercase J to make sure
that we are using the xz utility.
And there we go running time again
and let's figure out how long it takes.
As you can see, the time it takes to compress,
this file really takes a lot longer.
And that is because
of the compression algorithm that is used.
But the thing that matters of course
is what is the compression ratio.
And we are going to find out in just a second.
So what do we see?
Oh, wow.
One minute and 10 seconds.
That is again, more than three times
the amount of time as the bz2 utility.
Another thing that we really wanna know is what
about compression ratio?
So ls -l on /tmp files
.star is showing us
that the original archive was 339 megabytes.
Then we have the gzip archive, which is, well
shall we say a hundred?
The bz2 one is about 90.
And the xz compressed archive is only 78 megabytes.
So for 20% more effective compression, you need to wait.
Well, about 10 times as much
the difference between gzip and xz.
It's up to you,
what best fits your needs.
These are the different utilities.
Now you can use these utilities
on the command line as well
to compress as well as to extract.
So if I would use gzip, for example
on /tmp/files.tar
then we can see that, oh, automatically it wants to
to create a file with the extension.
And it's kindly asking if I want to overwrite and well
I don't want to overwrite you get the idea.
Gzip will compress and gunzip will do the decompression.
And likewise, you can use bzip2 and xz
from the command line as well.
But most of the times you will find yourself
using the compression utilities
as an argument to the tar command.