Hello the beautiful people.
And welcome to this video where you're going to start learning all about file archiving and compression.
And I'm sure you've heard millions of times about the benefits of keeping backups of your data, and
that's exactly what we're going to be covering in the next few videos.
In the next few videos, you're going to learn how to archive and compress your files in Linux to create
backups.
Now just creating the backups isn't good enough.
You're also going to learn how you can restore data from those backups in the future.
So when you need to uncompressed it, your data will come back out perfectly.
By the end.
You're basically going to be able to create and restore your own backups to make sure you don't lose
any important data.
And you're also going to learn about various compression algorithms so you can save the maximum amount
of space on your file system as possible.
So let's go ahead and jump right into it.
Okay.
So when you're compressing and archiving files in Linux, the first thing you need to know about is
something called a tarball.
Now I want you to imagine that you're at a shopping center or your local store and you're buying some
apples.
Now, let me ask you a question.
How would you make those apples after picking them up?
Easier to carry.
Will you put them in a bag?
Right.
And that's what creating a tarball is basically doing.
So creating a tarball is basically a way of putting your files in a bag to make them easier to compress
and make them easier to store.
And when you add files to a tarball, you make it possible to store all of your files in one place.
The tarball itself doesn't do any compression, but tar balls can be compressed using compression algorithms.
So archiving files is basically a two step process.
First, you make a table.
You make a tarball.
And then secondly, you compress the tarball using some kind of compression algorithm.
So let's go ahead and create our very first tarball.
So we're on our desktop and we can see that we've got file one txt, file two dot text and file three
dot txt and we're going to put those inside a tarball.
Now if I do an LZ on on these files and just have a look at them, you can see that they're all about
ten kilobytes in size, 9.8 kilobytes or about ten kilobytes in size.
And we're going to put all of these into a tarball.
So to do so, we're going to use the tar command.
The tar command.
Now, the tar command takes quite a few different options in order for this to work.
So first we type tar, then we need to give it three options.
So let's type a dash.
And the first option is the C option.
Now the C option lets the tar command know that we want to create a new archive.
The next is V, which lets the tar command know that we want to.
We want it to speak to us.
We want it to give us some feedback so we know how it's doing now.
V stands for verbose and it basically says, Hey, tar command, don't do this.
Silently, talk to me and let me know what's up.
Now the V option is entirely optional.
You don't need it to make an archive, but it's good practice to keep it there.
And the final option is the F option.
Now, the F option is so that it lets the tar command accept files.
So now we need to tell the tar command what we want to call our tarball.
Now, by convention, we end tar ball files with the dot tar file extension.
This is just a convention, so we know what they are called later.
So let's call it our archive dot tar.
And the finally, what we need to do now is we need to tell the tar command what's going to go inside
our tarball.
So we want to file one txt file two point thc and file three dot txt.
So let's just use a wild card to save some typing and put file 123. txt.
And with that we're ready to go.
So what we're saying is, hey, tar command, we want you to create a new archive.
So we give it the C option.
We're saying speak to us so we know what's going on.
So that's the V option and we're going to give it the F option so that it can accept new files and create
a new archive.
So let's just go ahead and press enter and we see that it told us what's going on and now we've got
this new tar file that's actually been created.
And you can see that it looks like a little box, like like a moving box.
So you know that it's that it's an archive.
And if we do an LZ, we can actually see that the tar ball file has actually been highlighted in red
just to make it stand out that bit more, which is quite nice.
So hooray, we've actually managed to create our first tar ball.
Now that command, this tar command had quite a few different options in it.
So what I've done is for all the commands dealing with archiving.
So in this video, in the next video, I've made a cheat sheet for you to download that details how
to do different archiving tasks.
So don't worry about memorizing.
Now you can find that in the resources section for the next video when we finish dealing with archiving.
Okay, so let's take a look at how large the file is by using LHS with the L option.
And actually what we're going to do is we're going to look for the ones that have dot tar in them using
using grep.
So we just see what has got tar on it to focus our results a little bit.
And we see that actually it's about 40,960 bytes.
Well, that's strange because we had three about 10,000 byte files and now we've got 40,960 bytes for
the tarball.
Shouldn't it be 30,000 bytes or somewhere near there?
Well, not exactly.
Well, think of the apples example.
If each apple weighed 100 grams and you have three apples and then you put them in a bag with a whole
bag, weigh 300 grams.
No, because the bag has some weight as well.
Right.
So what we're seeing here is just that in order to create a tar ball, we need to add some data.
So just think of the extra size being like the extra weight from a bag when you put apples in it.
It's just part of the convenience of building a tar ball.
But don't worry, when we compress the tar ball, it will be much, much smaller than the files would
have been on their own.
Okay, now we can tell that this is a tar ball by looking the dot tar file extension.
Right.
But remember that in Linux file extensions don't really mean anything.
They they usually just a convenience so that we can see it as humans, but they don't mean anything
necessarily to the system.
So to double check that it is a tar ball, we can use the file command that you learned about earlier
in the course.
So if we do file cleanly to clear the screen file archive dot tar and you'll see that it tells us that
it is indeed a tar archive.
Okay.
Now if we renamed this tarball so we renamed it to be our archive dot blam.
Let's say now if we do, if we do the file command on that so file of our archive, you see that the,
the Linux system wasn't tricked and it still knows that it's a tar archive even though it didn't have
the tar file extension.
So let's change that back because we don't need any more confusion than is necessary.
But that's just to let you know that the the tar file extension isn't particularly anything special
to the system.
But again, it might be to other programs that you have installed upon it, but you can always check
what the true nature of something is using the file command.
But the tar file extension is just something that allows you and potentially other users to know what
type of file it is at a glance.
Now you can actually take a look at what is in a tar ball without having to extract it.
So let's say you downloaded this this archive from from the interwebs and you wanted to take a look
at what's inside.
Okay.
Well, you can do that using the tar command.
And what you do is you give it two options.
You do the T option and the F option and then you tell it our archives.
TAR okay, so the T option means test label and it basically lets you check what's inside the tar file
and the F option.
It's just necessary in order to pass a file to the tar command.
So when we do that, it tells us that file one and file two and file three are inside the tarball.
So that's pretty cool right now.
We're going to come on to compression in a little bit, but first, let's take a look at how we can
get these files outside of our tar ball again.
Well, it's actually very simple.
First, let's delete the file whatever dot txt.
So they've all disappeared and we've got just our tarball here and we're going to extract the files
out of that.
Okay.
So let's try and do this now.
The way we'll do it is just it's actually very simple, right?
So you'll have the tar command and remember to create an archive.
You had C VRF and then you will grow our archive tar and then we gave it some files.
Okay, now to extract, it's very simple.
Instead of C for create you use X for extract and everything else is the same.
But you don't even have to give it any files because you're not putting any files into the archive.
It's just that tar x to extract v for for verbose.
So it tells us what it's actually doing and f is necessary.
So you can pass a file to the tar command and we'll we press enter we'll see that it is it has indeed
extracted out for us.
File one, file two and file three from the archive.
And we have those back in the, in the directory that we that we were in when we run the command.
So there we go.
Pretty easy.
Right.
And again, all of this is in the cheat sheet for us.
So now you might be thinking, okay, we've just extracted these files from the tar.
From the tar ball.
Is the tar ball now empty?
Well, actually, it's not.
You can just you can actually check that the files are still in there by telling it, just like you
saw before.
Checking inside with the TNF options, you can check that file one, file two and file three are still
inside the table.
So no matter how many times you extract from a table, the table still contains what's inside of it.
So it's like an A, it's a reusable bag that maybe you get from shops.
Okay, so that's pretty awesome.
Right now.
I'm going to break the video here for in interest of time.
And in the next video, we're going to be talking about how we can compress our tar balls to make them
smaller.
So for all that goodness, I'll see you in the next video.