Compression Utilities (Demo)

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey, Cybrarians.
00:00
>> Welcome back to
00:00
>> the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Goelz,
00:00
and in today's lesson we are going to
00:00
be covering compression utilities.
00:00
Upon completion of this lesson,
00:00
you're going to be able to understand why
00:00
compression utilities are important.
00:00
Then during the demo today,
00:00
we're going to use common compression utilities
00:00
such as gzip,
00:00
bzip2, xz, and zip.
00:00
Compression and compression utilities are commonly
00:00
used both in backup and in data transfers.
00:00
We've seen this little bit before as well in Module 18,
00:00
we saw that logrotate can handle low compression.
00:00
We saw some gzip compression with tar in the last lesson.
00:00
We're going to see this again later when
00:00
we discuss data transfer.
00:00
Now compression, like its name
00:00
indicates, makes files smaller,
00:00
which means they take up less space to
00:00
backup and they use less bandwidth to transfer.
00:00
The Linux plus exam explicitly
00:00
focuses on four compression utilities.
00:00
They are gzip, bzip2,
00:00
xz, and zip.
00:00
Those are the ones we're going to
00:00
cover in today's lesson.
00:00
The gzip utility was created
00:00
to replace a program called compressing.
00:00
It was created in 1992,
00:00
it achieves a 60- 70 percent compression rate
00:00
and has been the de facto compression utility
00:00
for a really long time.
00:00
You saw when we talked about tar,
00:00
I just only use gz for the most part.
00:00
Tar is very helpful here we can use tar
00:00
with the z option to do
00:00
gz compression like we talked about.
00:00
If you're not using it with tar,
00:00
you can just use gzip to compress the file
00:00
and then gunzip to decompress the files.
00:00
For example, if we want
00:00
to compress a file called file 1,
00:00
we do gzip file 1 that turns it into file 1.gz.
00:00
Then to uncompress or decompress,
00:00
we do guzip file 1.gz,
00:00
then compresses the file back to just file 1.
00:00
Now the bzip2 utility,
00:00
the bzip2 utility was created in 1996
00:00
and it has a higher compression rate
00:00
than gzip, but it takes longer.
00:00
That's because it uses multiple layers of compression
00:00
and algorithms to get that higher level of compression.
00:00
Bzip2 is the command that we use to
00:00
compress bunzip is used to decompress.
00:00
We can see the same examples there.
00:00
Bzip2 file 1,
00:00
creates file 1.bz2,
00:00
then bunzip2, file 1.bz2,
00:00
gets it back to file 1.
00:00
The tar command uses bzip2 as well.
00:00
But with bzip2,
00:00
we have to use a lowercase dash j option
00:00
to do bzip2 compression with tar.
00:00
Now the xz utility is a little bit newer,
00:00
that was developed in 2009.
00:00
Xz has higher compression than either bzip2 or gzip.
00:00
2013 it actually became the default compression algorithm
00:00
that's used for Linux kernel distribution
00:00
that we're using bzip2 before,
00:00
but xz is just much better, so that's what they use now.
00:00
To compress things with xz,
00:00
we just use the xz command.
00:00
Xz file 1 becomes file 1.xz.
00:00
Then to uncompress, we do unxz file1.xz.
00:00
Then if we want to use this with a tar command,
00:00
we can use the capital J option.
00:00
Remember capital J to use xz with tar for compression.
00:00
Lowercase j with tar to be a base of 2 compression.
00:00
Then the final compression utility we'll talk about today
00:00
before we get into our demo is the zip utility.
00:00
Zip utility is different from the others that we've
00:00
covered because it can operate on multiple files.
00:00
The other commands we talked about,
00:00
they just operate on one file
00:00
and they leveraged tar when we
00:00
want to archive a directory of
00:00
files or compress all of them together.
00:00
Files are copied into a folder
00:00
or archive file and then get compressed.
00:00
Then a new zip file is
00:00
placed in that same directory where we did
00:00
the compression and
00:00
the other compression utilities by comparison,
00:00
just replace the file that's being compressed so,
00:00
it turns it into a different file.
00:00
When we're using the zip utility,
00:00
we use the zip command to
00:00
compress and we use unzip to decompress.
00:00
As I said, tar is not needed here.
00:00
But let's take a look at all
00:00
of these with some demo time.
00:00
Here we are in our demo environment
00:00
and we're going to go back to our last lesson.
00:00
We're going to go ahead right away and create an archive.
00:00
We're just going to create an archive,
00:00
a tar archive of files.tar,
00:00
or we'll call it [inaudible] what's called
00:00
files dot.tar. We're going to do that.
00:00
Everything that's in my home directory,
00:00
that ends with a name files,
00:00
a home raw file.
00:00
Starts with file rather.
00:00
Now we can see the size of this file by
00:00
doing ls-alh on files.tar.
00:00
There we go and there we see that that is
00:00
20 K file here that we've created.
00:00
Now what we can do is we can actually
00:00
copy this a few times to make a couple
00:00
of different modifications here, so to speak.
00:00
Let's go ahead and do a copy on files.
00:00
tar, and we'll copy that to files 2.tar.
00:00
We'll also do another copy to files 3.tar.
00:00
These are the ones that we're going to use to do all of
00:00
our different compression work as
00:00
we go through the purposes of this demo.
00:00
First, let's go ahead and do a gzip,
00:00
let's do a gzip on files.tar.
00:00
We're going to do a bzip2 on files 2.tar.
00:00
We'll do a list here,
00:00
xz on files 3.tar.
00:00
Now we can do als- alh on files tar.
00:00
Now, we're going to see as at
00:00
these files have gone notably smaller.
00:00
We started out with a 20k files.tar.
00:00
If you look at the gzip compression,
00:00
we're down to 464 k.
00:00
If we look at the bzip2 compression, we're down to 408.
00:00
If we look at the xz compression,
00:00
we're down to 432.
00:00
Now if we want to uncompress these, we can do this.
00:00
We have to do this by doing gunzip.
00:00
We do gunzip on files.tar.gz.
00:00
If we want to do an uncompressed on a bzp2 file,
00:00
we do bunzip 2 files 2.tar.bz2.
00:00
Then we can do for xz, we do unxz.
00:00
We're going to do this on files
00:00
3.tar.xz, that is uncompressed.
00:00
Now, if we do an ls-alh on all those again,
00:00
we can see that they've all been
00:00
uncompressed and then they're back to 20
00:00
k. Let's last create
00:00
all of the archives
00:00
compress with each compression utility.
00:00
For example, what we could do is create a tgz file
00:00
by doing tar-create zvf.
00:00
Because we're going to use gzip,
00:00
we're going to call this one files.tgz.
00:00
This'll be on anything in the home rob,
00:00
that starts with the word file.
00:00
Now, we can do the same thing,
00:00
but we're going to do instead of 4gzip compression,
00:00
we're going to do it for bzip2.
00:00
We'll call this files 2.bz2 again, we'll do that.
00:00
Now, let's do the same thing,
00:00
but let's do it for x z.
00:00
Remember with xz we have to use
00:00
an uppercase J instead of a lowercase j.
00:00
This will be files 3.xz.
00:00
Now, once again we can do
00:00
an ls- alh on anything that ends,
00:00
it starts with the word files.
00:00
Now, we can see the final file size of these,
00:00
related to how they look when we
00:00
run them through a compression algorithm.
00:00
Files.xz ends up being 3.ok in size.
00:00
We end up having files 2.bz2b 1.7 k.
00:00
>> Then, our tgc file ends up being about 867 bytes.
00:00
>> With that, we've reached the end of this lesson.
00:00
In this lesson we covered
00:00
the importance of compression utilities.
00:00
We talked about how to use
00:00
the most common compression utilities,
00:00
such as gzip, bzip2,
00:00
x z, and zip.
00:00
Thanks so much for being here
00:00
>> and I look forward to seeing you in the next lesson.
Up Next