Now, as we continue to add things
to our backup drive,
we'll notice that the spaces rapidly being consumed.
Now, the best thing we should do in this scenario
is to compress the files.
So we're going to go over three different methods
of compressing these files.
We're going to go through and use the gzip, the XZ method,
and the bzip2 method.
All right, so the first thing we're going to do,
we're going to go to our backup drive.
Okay, I'm going to list out.
Now, if we see our employee data.tar file,
it's roughly 10 kilobytes.
Okay, so we're going to compress this using gzip first.
So we're going to use the sudo bash command.
So you remember, when we use the C command,
this will allow us to simultaneously create the file
without deleting the current one
'cause by default, it replaces the current one
and we don't want that.
Okay, now we see it compressed by 97.5%.
So let's list this out.
And now we see that it's now from 10 kilobytes to 290 bytes.
That is a significant reduction.
And this should be a practice that you use frequently
when you're storing data.
Next, we can go through the process
of uncompressing this archive with tar command.
And one good thing about the tar command,
it allows us to use the z option
which will decompress simultaneously
so we won't have to decompress
and then remove the files from the tar.
We can do it all at once.
So we list this out.
We can see the employee info folder
has been removed from the tar
and it's also decompressed simultaneously.
Next, we're going to compress and decompress with the XZ tool.
So again, let's do sudo, new xz,
and the -k, that means we're going to keep it.
And again, v always means revolve for the most part.
Okay, we see here that it's 100% complete.
That's the progress of the compression.
And it's .03, which indicates
that it's 3% of the original file size.
But to note the differences between XZ and gzip,
XZ is usually better at compression,
meaning, it's a higher ratio
so it can make the file a lot smaller than gzip,
but gzip has an advantage in speed.
All right, let's list this out really quick.
In this case, our starting file sizes were so small.
The XZ actually ended up being a bit larger
than gzip this time.
But normally, XZ will have these smaller file sizes.
All right, next we're going to decompress this XZ file,
now a tar.
Earlier we used the Z command.
Now this time, we're going to use the capital J,
that's going to allow us to do that, .xz.
All right, that went through successfully.
Let's list this out.
And we see the employee info is back in there.
Last but not least, we're going to use the bzip command.
And this is a nice balance between XZ and gzip.
So we're going to use -k, that will keep the file,
employee data.tar.
All right, and again, now we're going to decompress it.
We're going to use the tar, okay xj, tar.bz2.
And again, that listed it out.
List this out.
Now we can see the employee info is back in there.
Okay, just walk through how to compress files
using the tar files
and how the tar command implements options
that allows us to decompress as well as extract the file
from the tar itself.
Now, typically the XZ compression method
compresses things a lot better,
but we see this time with the gzip,
it actually won out on this particular test.
But overall, the XZ is the better method,
gzip is the best for speed
and the bzip2 is the best balance between the two.
Thank you for sticking me through this lesson
and I'll see you in the next one.