From the course: CompTIA A+ Core 2 (220-1202) Cert Prep

Working with folders

- We work with folders at the command line all the time. Now, in other episodes, we've been navigating around folders and that's fantastic. But there are situations where you're actually going to have to be creating folders or even deleting folders from a command line. There are literally thousands of reasons to do this. You're building up a bunch of driver's disks that you're going to be keeping on a thumb drive, or you've got a bunch of ISOs that you're pulling in from a script and you're doing it all from a command line, and you don't want 'em laying all over your computer. So you need to not only, we're going to be doing this by hand in here where we're typing commands, but keep in mind in other episodes, all of this stuff you're learning for everything in the command line can be integrated into scripts. And that's where the beauty really kicks in for command line. So you got to learn how to make directories, make folders, and delete them from a command line. Let's do it. All right, so here I am at a D drive and let me type dir. And you can see right now all it has is three folders in it. So what I want to do is make a folder, and I'm going to call this folder mike. So to make something, you want to be in the folder above it. And this is exactly where I want it. So to make it, you just type md, make directory, and then the name that you want it to be. So I'm going to type in md mike. I hit enter, nothing happens. Remember, at a command line, if nothing happens, that's usually a good thing. People start doing these commands for the first time when they learn this stuff and they do something right, they're expecting a $5 bill to come sliding out of the computer. Doesn't work that way. When you make a mistake, it will slap you in the head. But when you do something right, you often get nothing at all. So to see the results of this, I got to type dir, I got to see it. And there is mike right there. Now while we're in here, this is a good opportunity to talk about capitalization. Windows doesn't really care about capitalization and Linux does. Now I've got a directory in here called mike already. What I want to do now is I'm going to make another directory called capital M-i-k-e. Let's watch. (keyboard clacking) So dir one more time. We see that mike is there, right? Let me clear the screen. So I'm going to do md Mike, ready? Windows does not look at capitalization. So when you're working in a Windows environment, keep in mind that you're only going to have one mike directory. In Linux, I could have a capital M-i-k-e, lowercase m-i-k-e. I could just make a capital I in mIke. So, but in Windows, it doesn't matter. Oh, by the way, did you notice something? You just got an error. An error popped up on the screen. Oh, I got an error. No you didn't, you got good information. Yeah, you made a mistake. But that's the beauty of a command line. You see a mistake, you're like, ah, nothing blew up. I don't see any smoke, we're in good shape. I love errors because they let me know when I've got a little problem. All right, so let's clear this one more time. Let me do a dir to make sure we're all together. There's mike, in fact, if you want to make sure it works, look, we'll just jump right into the mike folder. Cd mike, there it is. I type dir. I'm inside the mike folder. Now if I want to, I could make a folder in a folder if I want. So make a directory mike again. (keyboard clacking) There's nothing wrong with having multiple mike folders, they just can't all be in the same folder together. So yeah, I can have a folder called mike with a subfolder called mike. No problem, I just can't have two in the same folder. Got the idea? All right. Now I'm going to go ahead and now what I want to do is delete a folder. So I'll type dir one more time. There's the mike subfolder in the mike folder. So to get rid of it, all I have to do is type rd. And then the name of the folder I want to delete. (keyboard clacking) Type dir and it's gone. So let me get back up to the root directory of the D drive. So I've got these four folders in here. So let me go ahead and delete the top mike folder. And it's gone. Fantastic, now watch this. Do you see that folder called VMs? And by the way, this is all the virtual machines I use in this course. Let's just go ahead and wipe 'em all out. You ready? Aha. Oh look, another error. No, it's not an error, it's good information. You can't delete directories that have anything in them. So that's kind of a nice thing and we take advantage of that particular feature. Sounds like fun? Great, let's do it again in Linux. So now that I'm in Linux, let me do a quick ls, show you that I'm sitting here in my home directory. Everything's fantastic here. So to make a directory, all I have to do is type in mkdir. Now to make this more interesting, I'm going to go ahead and cd into my Desktop. And by doing that, we'll see it graphically appear as soon as I make it. So let's go ahead and make something called mike. Ta-da, you've just made a folder. Now because it's Linux, oh, and by the way, I'm about to hit the up arrow key. This is convenient, huh? We call that history. And I'm going to make a directory this time with a capital M. Ah, see, Linux knows capitalization. Don't try this in a Windows environment. It will never work. Now, to get rid of a directory, we just type in rmdir. So to get rid of capital Mike, I'm going to type rmdir. I'm going to type capital M, I hit that tab key 'cause it's the only folder in here that starts with a capital M. And it's gone. Yes, we're on a roll. I'm going to hit my up arrow. Change that capital M to a lowercase m. (keyboard clacking) And I've deleted the folders. This seems pretty simple, but when we get into scripting and things like this where we need to start making directories within our scripts, you are going to love what you just learned in this episode.

Contents