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
Worked example: separable equation with an implicit solution | Khan Academy
We’re given a differential equation right over here: cosine of y + 2, this whole thing times the derivative of y with respect to x is equal to 2x. We’re given that for a particular solution, when x is equal to 1, y of 1 is equal to zero. We’re asked, what…
Capturing the Year in an Instant | Podcast | Overheard at National Geographic
Uh, the fire is approaching. It’s making this really loud wind, uh, sort of howling. You can hear the fire coming over the ridge line. Uh, just in the last 20 minutes it has become visible, so it jumped the ridge and is getting closer. That’s National Ge…
Space Station Transiting 2017 ECLIPSE, My Brain Stopped Working - Smarter Every Day 175
Five, four, three, two, one, transit. Hey, it’s me. Destin. Welcome back to Smarter Every Day. August 21st 2017. It’s Matt Whitman, it’s Trevor. We’re in the middle of Wyoming. This is a really special spot. You have to understand we’re on a reservation,…
Breaking Into a Smart Home With A Laser - Smarter Every Day 229
(Smart Lock Opening) (Smart Lock Dings) - [Destin] It just worked. - [Ben] Yep. - Alexa, Okay Google, Hey Siri, set a reminder to subscribe to Smarter Every Day. You have a microphone listening to you in the room right now, what I just did probably worked…
Lion Falls From Tree During Rescue From a Wire Snare Injury | National Geographic
We pretty much picked up on finding that Orinda at a point where she was treated about two weeks back. So even though the snare was removed, we saw that over about a two and a half week period, her conditions started again to rapidly decline. So we find …
Channing Tatum Makes Fire | Running Wild With Bear Grylls
CHANNING TATUM: God, all these stones, man. Look at them. They’re just massive boulders. BEAR GRYLLS: Nope, it’s a dead end. So all of this area is endless, like, dead ends. You reach a cliff face or you reach a boulder you can’t get over, you try and go…