Loading
Lesson 04
Courses / Learn Unix Linux Bash Command Line Terminal Tutorial
Using the COMPRESS Command for Compression and Decompression of TAR Archive Files in Linux

Video Transcript

I am going to teach you how to use the command compress to compress an archive in Linux. You can use this in any Linux based system. It's Linux or macOS. So the compress command, it's no longer that popular these days. Usually people would use gzip or bzip2 for a Linux system. But I'm going to teach you how to do it anyway if you ever come across compress. Because I am using Ubuntu Linux 18.04, compress is not installed by default. So I actually have to install it using apt. The command has a different name. It's called n-compress. Okay so let's get started. Here I have some... So I have an archive, a tar file that has two files inside the archive. One being notes.txt, the other being sample.jpg. I did tar-tvfarchive.tar to see what's inside the archive without extracting it. The dash t stands for just check the contents of the archive, v for verbose, and f to specify the tar file. Now if I try to do compress in the name of the archive, it's not going to find it. You likely will see something if you use Ubuntu it's going to tell you hey you might want to install and compress. So I'm going to do sudo apt install and compress to get it. I already had it before so that's why it's going to be really quick to install. And now I can do compress archive.tar. And if I check ls-l for the contents of my current directory I see that archive.tar remains there and it doesn't seem that anything changed. And that is because compress could not reduce the file size. So you might find that compress if you try to use it with a tar archive sometimes it will not achieve any level of compression and because of that it won't do anything. It would just leave the tar file as is. Now to illustrate this point and to actually get something to be compressed I got this file called image.bmp that if I include in the archive will actually allow us to see compress actually doing something. And the extension would be .z right, .tar.z. Capital Z. Now let me see what I can do here. I would like to add it to the archive. So in order to add that to the archive let me see what I can do here. There's a command for tar that allows you to append to the archive and that's the r option. So if I do right now if I do tar-tvf archive.tar we see there's on two files no.txt and sample.jpg I want to add image.bmp to that tar file I'm going to say tar- and the option is going to be dash r vf. v is for verbose and f to specify the file name archive.tar and at the end I'm going to say the name of the file I want to append. In this case image.bmp. Now let's have a look again at the archive.tar with tar-tvf and I can see image.bmp is now included in addition to notes.txt and sample.jpg. Now let's try to use compress again I'm going to say compress archive.tar and I'm going to do ls-l and I can see now that archive.tar became the file archive.tar.capital z. So in this case compress was able to reduce the file. So I achieved some level compression therefore it actually made the tar.z file. Now let's learn how to uncompress. Well intuitively it would be just uncompress followed by the file name right so let me make a directory here. Let's say Dear 1 and I'm going to see Dear 1 and try to decompress here. Now typically you would use uncompress but because I'm using Ubuntu and if I read the manual for compress it's actually uncompress.real and there's a note here saying that usually it would be uncompress but from the case of Debian you have to use .real because there's a conflict with it says here this has been done to avoid conflicting with the more commonly used program with the same name that is part of the gzip package. So there seems to be a conflict of the gzip package that's why they have to we have to use uncompress.real. In my case I don't know if you're going to need it just try with uncompress or check your manual page man-compress to see if you have to do that or not. In any case I'm going to say uncompress.real.to-goat-one-level-up archive.tar.z so this is going to uncompress that here. Not here right? I didn't mean to extract yet so I'm sorry let me go back one level up it's actually going to do the uncompression wherever it was before so you can see archive.tar is back and yeah if I wanted to extract a dear one I would see dear one and do that tar-xf with the file name being dot dot slash archive.tar and then that would work right? I'm going to go there cd to one tar-xf if you want to be verbose add the v dot dot slash archive.tar and you can see they're all here and if I go back archive is there too. So that's essentially it if you want to compress something you say compress space file name tar file name and if you want to decompress you want to say uncompress in my case uncompress.real space the name of the tar.z file. You know compress might not always be able to compress anything so you might end up with the same tar file without any compression in that case there wouldn't be a dot tar.z extension it would be just dot tar because it couldn't achieve any level of compression so it didn't do anything. So that's it for this video and I hope to see you next time. Goodbye.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: