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
How AirBnb will Crash the Housing Market
Here’s how Airbnb could crash the U.S. housing market. There are over 1 million properties listed on Airbnb here in the United States. In recent years, there’s been a huge trend of small investors buying single-family houses to then list on short-term re…
Flying from Japan | 19 hours flight vlog🇯🇵
Hi guys, it’s me Ruri. Today I am back with another super long travel vlog. Our flight is going to be around 19 hours, and we’re gonna fly from Japan to the UK first, and from there we’re gonna fly back to Turkey. This is the Haneda Airport. If you watche…
We Worry About Problems We Don't Even Have | Eastern Philosophy
Two people attend a house party, where they socialize with the same guests, drink from the same beer tap, and are exposed to the same music and atmosphere. They decide to share a taxi and drive home when the party is over as they live closely together. “…
Meditation: Prioritize your mental health and happiness in self-isolation | Sharon Salzberg
Although everyone is welcome to the Big Think live webinar, today’s topic is mindful isolation: how to prioritize your mental health and happiness. I couldn’t think of a more appropriate topic to discuss right now. My name is Derek Barris. I’ve been a Big…
Putting a Penny on John Wilkes Booth's Grave
Let’s talk about Robert Todd Lincoln. He was Abraham Lincoln’s son, and in 1863 or ‘64, he slipped at the New Jersey train depot. He was almost crushed by a train car, but his life was saved when a man reached out and grabbed him, pulling him back. That m…
Situational irony: The opposite of what you think - Christopher Warner
Translator: Andrea McDonough Reviewer: Bedirhan Cinar Picture this: your friend and you are watching a sitcom, and a sassy sidekick walks into a room, carrying a four-tiered wedding cake. He trips, falls, and face-plants into the cake. Your friend double…