Terminal Lesson 5
Mad kids online, and today I'm going to be showing you one more terminal trick, and it's actually worth your time. I'm gonna be showing you today how to zip a file into a zip file and how to zip multiple files.
So I'm gonna be demonstrating this to you on my desktop. Let's see my desktop—normal stuff here and some hard drives and stuff. So right now, first of all, I'm gonna make a new document called hi. Inside of this, I'm just gonna type some random stuff.
Now, when my desktop is hot, now we all remember this—how this works. We're gonna zip up hi into a zip contrast file or folder. See, what we're gonna do is we're gonna type zip zip space ./.hideout.zip ./.hi
. Let me explain this: zip
just zips something. The first parameter, which is ./hideout.zip
, is where we're gonna zip, and .
means my active directory, like my PWD.
So right now, if I type PWD
, I'm in /user/Alex/desktop
. That means /user/Alex/desktop
, that's what that means. /hi
and it's actually hideout.zip
because whenever you make a zip file, you want to end its name with .zip
. Then, the last parameter is the file for zipping into the zip file.
So now we hit enter, and right there it says, "adding hi, stored at zero percent." Now here's hi.zip
. Let me just throw it—hi is in the zip file right here, and I can double-click hideout.zip
, and hi.zip
extracts and then makes hi right there on my desktop. I can open it up, and there's hi indexed at it.
So now I'll throw out both of these when you have a zero, and on Apple, to throw it out, add zip. Then you have a zip file, and you double-click it to open it up. It will release everything that's inside of it onto the active directory.
So now let's do that a different way. We're gonna do a nano hi
again, make just a random hi. Now hi's back on my desktop, and I'm gonna zip up hi. Actually, I'm gonna move hi to rename it from hi to hi1. Now hi is now hi1.
I can then take hi1 and zip it into the same hideout.zip
. So already we can see hi is in hideout.zip
, but now hi1 is gonna be added to it too because we're gonna do the same zip command, and hideout.zip
already exists. That's okay, and we're going to zip up hi1.
Now we hit enter, and it's added hi1 to hideout.zip
. We're gonna delete hi1 from my desktop. Open hi.zip
, and now if you have more than one file in a zip file, it will create a directory with the zip file's name, except without the .zip.
So now here's hi; we open up hi, and here is hi and hi1. So now let's throw this out. Let's do one more thing: We're also going to zip up into hi.zip
. We're gonna zip up documents into hideout.zip
.
Now this is a little different because we're doing a directory. We do the same thing. We're gonna check documents here, so ./documents
, but we're gonna have to do zip -r
for recursively. And you know, arm -- sure means recursively remove this, move this recursively, whatever.
Our zip -r
recursively, and it said all this stuff will come up. Whenever you zip any file into a zip file, it will take a while. So now it's taking a long time to zip up something because it's actually a large file.
So I'm just gonna do a cut here into the list. Unzip it. Okay, so we're done zipping everything into hi-dive.zip
right here, and if we open it up, it will take a long time to extract, and it says "on archiving." This is gonna take a little while, but it's worth your wait.
Now all the documents inside of it and the directory inside of it will appear on my desktop.
So now it's done loading. Here's hi, and there's documents—everything in hi, and in highlights. If I'm gonna throw out hi, actually, I'm just gonna do an rm hi
—save space, and I'm gonna have to do an rm -r hi
.
Then I'm gonna do an rm hi.zip
, so now my desktop is clean once again. So let's just make a new zip file just of documents, and I'm gonna show you one little thing. So I'm going to do another cut here as it zips up documents.
Okay, so now we have hi.zip
. Let's just demonstrate one more thing with hi.zip
. Zip plenty of stuff into it. It's actually just got documents in it at this point.
So now what I'm gonna show you is how to use the unzip
command. Now look at this. We type unzip
, and this is actually going to be a special experience. This means hi.zip
.
What this does is the equivalent of double-clicking it to unzip, except if documents already exist on my desktop, it's gonna try to put documents on my desktop again. That's not gonna work out. Normally, when you do it with the GUI, documents one will appear on my desktop because there's already documents, but on this, it's gonna ask us what we want to do.
So let's do this. Now it says, "replace + y for yes to replace my Documents folder." No, we don't want to replace it. For no, that would just cancel the unzip because there's no other file, or you know, replace all.
And our four rename—let me type the letter we want and hit enter. So I'm gonna rename documents, which is trying to unzip to documents one right here, which is document small. Now this wants us to unzip everything in documents, and so we can either rename everything or do whatever we want.
So right now, I'm going to type our four rename documents. So now this is creating all the documents I want on my desktop. I'm just gonna cancel it at this point by pressing Ctrl+C.
Now say I dragged hideout.zip
into another folder like programs. Just drag hideout.zip
into here, and I unzip it here, whatever I want to do with cd programs
. It will just unzip it normally.
Now we type unzip hidoc.zip
and hit enter. Looks like I typed unzip wrong, and now it's gonna do all this crap for inflating, etc.
We can come over here to this find your window—see documents has appeared here. Everything in documents right now is being created, so more and more stuff is gonna come up here. Close this, and that's pretty cool!
And it's unzipping—it's done unzipping. Now let's just leave these documents on my desktop, go into programs, get rid of documents.
So that's how to zip a file folder, how to unzip something using the unzip program. And thanks for watching terminal lesson 5. Subscribe to Mac Heads at youtube.com / Mac Heads 101. We appreciate your watching, and goodbye.