Now, it's all right, you don't need to worry.
You don't have to do any crunches or any exercises or anything like that.
We're just taking a look at some of our compression utilities that
we're going to be able to find inside of Linux.
Most commonly, we use the gzip utility and gunzip to expand gzipped files.
But we also on some distributions have bzip2 and bunzip2 to unzip.
Usually,
we're also going to be able to find the xz command
to give us very good compression, and it's one command,
‑z to compress and ‑d to decompress, although ‑z will be the default,
so we don't need it when compressing.
But each one of these commands can be incorporated,
if they exist on your system, with the tar command.
So to create a zipped up archive all in one go without our tar command,
we can use a lowercase z to implement gzip,
lowercase j will implement bzip2, and if we use the uppercase J,
then we're implementing xz compression, again,
the greatest compression that we're going to be
able to get with these utilities.
Now, having then looked at this,
we might think that we're only running the tar command,
when we're using the option to compress files.
However, they do actually still run independently,
and we can go through and take a look at this from the command line.
Here I'm using the uppercase J,
so we're implementing our extreme, or xz, compression.
I'm running as a standard user, so we don't get the errors on the screen.
I can redirect through to dev/null, so 2,
our error output, is redirected through to dev/null.
The ampersand at the end just indicates then that we are backgrounding our task.
That's going to give me probably about 12 seconds or so with the xz
compression to be able to run the ps command.
And when we take a look at the PS command in our current terminal,
we can see that we have both the tar and the xz
command running as different processes, so process ID 91 and process ID 92,
or 5091 and 5092.
So again,
we're allowed to open up the bonnet of Linux and take a
look at what's happening underneath.
But really, to understand what's going on,
you're going to need to fiddle around with the nuts and bolts yourself.
So when we go out to the demonstrations,
please ensure that you're able to follow through the demonstrations to ensure
your learning is really going to be thorough and complete.
Now our first demonstration is going to take a look at how
we can go through and compress our files.
So let's take a look at this first before we move
onto some other demonstrations.
And here we are at our glorious command line.
So let's go through and just take a look and remind
ourselves of the size of the etc.tar file.
As we go through and take a look at it, we can see it's 23 MB,
and this is uncompressed.
We can go through and compress it.
We compress with our utilities, a single file, this is now a single file.
So I can go through and use then gzip and then the etc.tar file.
That's now compressed.
We can see it didn't take too long,
but as I go through and just take a look now at the etc.tar.gz file,
we can see that we've gone from 23 MB down to 5.2 MB.
So it was relatively straightforward.
When I go through and do an ls ‑l just in the directory,
we can see I no longer have the etc.tar file. Automatically, it
took the tar file and then compressed it,
adding in the gzip extension.
If I want to unzip it,
then the reverse command is gunzip and then etc.tar.gz. Again, when I go
through now and just to a long listing in the directory,
we can see I have the etc.tar file.
I no longer have the gzip file, as it's been expanded into our archive.
Now having had this unbridled excitement with our gzip command, why
don't we go through and try the xz command? Now I don't need to use
any options with this, because, by default, it will compress, so I
can go xz and etc.tar.
We can see now having hit the Enter key,
it's taking a little bit of time as it goes through and compresses the data.
There's a lot more CPU time being used to create our file.
But then hopefully, as we go through and run our long listing,
we can go through and see the size of our file. Might be a little
bit easier to go through and see with our ‑lh, but we can see
that we've got the etc.tar.xz file.
But if we want to check on that file size,
it's now 3.2 MB from our 5 MB or so before.
So we've gained a little bit,
even though we've taken more CPU time. And it really is just
balancing the file size with the CPU time that's being implemented
to get us that compression. Now If I go back now and just take a
look, if I want to expand it, it's xz ‑d.
And obviously, I've got to put in the file name now, so
etc.tar.xz as the correct file name.
And again,
that will have removed the .x extension and decompress the file back to etc.tar.
So working very much in the same way as our gunzip utility,
expanding the file and putting the file name back to what it was
before and, of course, the original size.
But this has then shown how we can go through and use some of our
compression utilities independently by themselves, but let's look
now at implementing it with our tar command so we can back up and compress at the same time.