Yes,
we want to dive out to our command line now and look at
implementing compression within the tar command.
But we can also compare the time it takes to include that compression to
give us real evaluation of what's happening on our system.
So diving out to find ourselves a glorious Alma 8 command line,
we're going to go through and take a look at how we can
implement our compression and time it.
So we're going to begin by starting off with a
decompressed or totally uncompressed file.
Implementing the time command in front of any command
will show you how long it takes.
So when we go through and run our tar ‑cf for our etc.tar file,
we can overwrite the existing one, from our etc directory.
Now we know we are going to get errors,
so we can go through and implement redirection of our error
output through to the device /dev/null,
so a special device file that will just ignore the data.
And we can then go through and hit our big Enter key to be able to
see that this took virtually no time at all,
0.08 seconds, and we know then that's going to deliver us a file size of,
say, 22, 23 MB or whatever it was.
Now with that then implemented, that's no compression at all.
Using options, we can implement the compression,
even if it's independent of the tar command.
So z will be our gzip compression.
We can use then etc.tar.gz and then again hit our big Enter key.
Now this really doesn't take long, 0.7 seconds,
so three‑quarters of a second, by the looks of it.
But we know we've got around about 5 MB of disk space,
compared to the 20 MB that we had before.
Well, okay,
let's just up our compression just a little bit and take
a look at our extreme compression, or xz.
So with that, we're going to implement the uppercase J,
make sure we change our extension.
The extension doesn't really matter.
It's more help for us,
but I don't want to be overwriting any of these files so we
can then compare the file sizes at the end.
As we then go through and take a look at this now,
it's taking an age, for goodness sake, but an awful lot longer,
10.6 seconds, so 10‑and‑a‑half seconds.
So we can see then the time.
We're only really interested in the real time but
massive amounts of difference there.
As we go through and do our long listing with our human‑readable format,
and we can list just the files that we're interested in,
so etc.tar*, we can see then that we start off at 22 MB,
where we're not using any compression at all.
For our gzip file, then it's 5.2 MB and cost us three‑quarters of a second,
whereas the 3.2 MB then cost us 10‑and‑a‑half seconds.
So even though it took a lot longer, we got a little bit extra compression,
but it's a matter of balancing up the time taken, the CPU cost, as well as the cost of your disk storage.