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
Africa’s Pristine Delta in 360 - Ep. 1 | The Okavango Experience
That first moment sitting by myself on an island in the Okavango Delta was the most profound moment of my life. It is, to me, a wilderness beyond comparison. The Okavango Delta is Africa’s last remaining pristine Witkin wilderness. It is an oasis in the m…
Intralase LASIK Procedure with Fear-o-meter and Pain-o-meter
Hey, it’s me, Dustin. I had LASIK surgery here at some random doctor’s office. I’m not going to tell you which one it is, but, uh, anyway, the surgery went well, and I recorded it. Well, kind of recorded the video playing of it, so here it is, check it ou…
"The MILLIONAIRE Investing Advice For EVERYONE" | Kevin O'Leary
I say start small, start small! Dip your toe in the water, see how it works, get a feel for it. So why are people not investing? They’re scared, disciplined, scared! Evan, no, they’re scared. But it troubles me immensely now to realize that there’s a hund…
Peter Thiel on the Triumph of the Counter-Elites
From the Free Press, this is Honestly, and I’m Barry Weiss. President-elect Donald Trump is announcing the appointments of additional members of his administration today. Tonight, Trump is announcing that a Department of Government Efficiency will be led…
Think on it | Barkskins
Mathilde: One only has to say the word “English,” and they come running like sick black dogs at low tide. Captain: Well, I heard about your selfless heroics with the Iroquois and the tragedy with the priests. Well, I suppose there’s nothing more that nee…
Watches You Buy As You Get Richer
As you get richer, things change, right? Including how you spend your time, but also how you look at the time. Ever wonder what your watch says about you and your bank account? Well, from the first costume you buy with your allowance to the Rolex you flau…