yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Terminal Lesson 18


4m read
·Nov 3, 2024

Hey guys, this is Maads. On and today I'm going to be showing you how, um, different methods of compressing, archiving, and doing both at the same time, and what good terminal commands that do these are.

So first of all, let's get this straight: compressing and archiving are two totally different things. Archiving is something kind of similar to what tar does. It takes a directory and turns it into a file, or it takes a file and turns it into a compressed file that you can then take the tar file of whatever you've tarred and move it somewhere else quickly and efficiently.

Compressing is when you use some kind of algorithm to smartly go into a file and find patterns and change those patterns into one simple pattern that never repeats; it just says it repeats. So that way, real files, um, get generated from them. It's turning um a file into a, um a real thing; it's turning a um file into a compressed version of the file that can be decompressed.

Now, let me explain things that do these. Zip, which is probably the one you're most familiar with, compresses and archives. Let me demonstrate what I mean. When you have a folder, you can zip it and it'll create one zip file for the folder that is smaller than the folder was. So it compressed and archived.

Tar just archives; it takes a folder and turns it into a file or something like that. Gzip just compresses. You've probably never heard of gzip, but there's a command gzip which literally just takes a file and turns it into a .gz file. It doesn't do anything; it can't do anything with directories really.

So let me demonstrate all these commands. First of all, I'll CD to my desktop because um that's where all my files are. So now all I need to do is say I have this file file.text. First, I'll zip it. By the way, you should have watched other terminal lessons before this one. So here's a file.text.zip. It's 12 kilobytes, while the original file.text was 1,600 kilobytes. So as we can see, it really went in there and did a good job compressing and archiving this.

So say I have a folder and I have two files in that folder, okay? So now this folder has two items in it. Okay, so say I want to zip this folder. I just do a zip -r folder.zip folder. So now I have a zip of this folder, and then we have four items in this folder, but it comes out with one zip file. Then if I delete this folder and unzip this ZIP file, I have the entire folder back because it was not only compressed but archived as well.

So that's my zip. Say I want a tar. I'll just say here is my tar of this folder and it's one file for the folder. So if I delete the folder and untar the tar, here I have the exact folder back. But if I take a look at this, 1.6 megabytes, this is 1.6 megabytes as well. So it's practically the exact same size, even a little bit bigger.

So why does this happen? Well, if you take a look, we open this up with text edit. I'll just use Taco right here. We actually have the contents of the files directly inside of this, as you can see, because tar doesn't compress. So the reason that people don't just have tar files sitting around anymore is because they waste space when you could compress them.

So let me just gzip this folder and show you why gzip has nothing to do with archiving. Type gzip -r folder. Watch this! Now I've gzip this folder; the folder is still there. There's no folder.gzip. When I open it up, every file inside of it is gone, and instead there are gzipped versions of the files that within them contain the actual files.

So how funny is that? I think that's pretty funny the way that gzip works. Um, so gzip ultimately just compresses, not archives. So the way to use tar and gzip to archive and compress is obviously to make a tar of whatever and then gzip that tar. So you do gzip space and then the tar file.

So here's the tar.gz. Here's my folder, so tar.gz. There's an easier way to do that; you just do tar -czvf folder.tar.gz. Yeah, whatever folder, and I'll delete this.

Okay, so here, tar can also do this. So if you watched my other terminal lessons, you'll probably be comfortable with what I'm doing here. But gzip is obviously just for compressing. But I like gzip more, actually, because it can just be used in a flat way. I can take one file, gzip it, and send it to my friend with a practically simple as hell terminal command.

So gzip is a good way to just take files and make them smaller. Tar is a good way to take files and make them into one. And zip does both most conveniently because you can just, on a Mac, right-click on something and click compress and you come out with a zip.

So that's just my opinion on compression methods. I will point out that gzip is used on stuff like HTTP compression, which can use gzip. So gzip is very important, basically.

Um, so gzip, the command is gzip -r folder or gzip file. So that's how to use gzip, and that's, um, what compression and archiving is.

So thanks for watching. Maad, one, subscribe and goodbye.

More Articles

View All
Zhou, Qin and Han Dynasties | World History | Khan Academy
[Narrator] What I’m gonna do in this video is give us an overview of the first significant dynasties in Ancient and Imperial China. Now, in a previous video, we talk about the Xia dynasty, which we’re not sure whether it exists because we don’t have a l…
15 Things That Scream “I’m pretending to be Upper Class”
Put your guest bag and your Gucci belt away and pay attention. All right? If you care if someone thinks you’re rich, you’re not that rich, so let’s be honest about this. Here are 15 things that scream, “I’m pretending to be upper class.” This is the third…
The AI in the Box
I have an idea for a Sci-Fi story that I’m never going to write so here it goes. Our two AGI researchers are building an AGI that they’re putting in a box so it can’t get loose and threaten humanity. There’s also a separate researcher, unconnected to thes…
Example identifying the center of dilation
We are told the triangle N prime is the image of triangle N under a dilation. So this is N prime in this red color, and then N is the original; N is in this blue color. What is the center of dilation? And they give us some choices here: choice A, B, C, or…
What feels like play to you, but looks like work to others?
I think for everybody there is something that they do that other people think is work but is effortless for them. Their friends will basically say to them, “Oh, I can’t believe you can just do that without hating it.” Everyone’s got something like that, a…
Can Bitcoin Hit 100K? | Kitco Interview
There’s a lot of misinformation about the mining in Bitcoin. They are not going to buy Bitcoin until this ESG issue is resolved, period. Let me be very blunt about this: I would say right now less than one percent of global institutions and sovereign fund…