1. Understanding the CLI
One of the great things about being an adult in today’s society is that we have all of these wonderful graphical user interfaces. I’ve got Windows on my Windows desktop, and I’ve got beautiful Mac OS screens. Even Linux on their desktops is absolutely amazing. I just take my mouse and click on stuff, and I can open programmes, delete files, format hard drives, and do all kinds of stuff. However, deep within every operating system on the planet is an alternative way to get your computer to do things known as the command line interface. The command-line interfaces are conceptually very old, but they’ve been kept as up-to-date as any GUI. And if you’re a real nerd and you want to get real work done, you will work at the command-line interface. Excited? You want to see one? Hey, I’ve got a Windows system right here. Let’s take a look. So just type CMD, and you’ll see this thing called a command prompt come up, and TADA! My friends, you are looking for a command-line interface. Now, when it comes to command-line interfaces, this is just one choice. You can have lots of different command-line interfaces. These different alternatives are known as “shells.” Let me show you another one in Windows. So now I have an alternative command-line interface, a different shell called PowerShell. Now, if you look at these at first, you might think, “Well, one’s blue and one’s black, but what’s the difference?” There are huge differences, which we’re going to be discussing throughout the episodes in this particular chapter. So brace for impact.
Now keep in mind that there are shells all over the place. For example, if I’ve got a Linux system, I’ve got a totally different shell there. Give me a second; I’ll bring up a Linux system right here and show you yet another shell. Here I am in Ubudu Linux, and I’m going to fire up this thing called a shell. Look at me, double-clicking like a Windows guy. Now if you take a look here, this looks a little different from those shells we saw in Windows, but this is what we call a bash shell in the Linux world. It doesn’t stop here. Macs have these as well. You want to take a look at a Mac’s shell? I’ve got one right here. Let’s take a peek. There are all kinds of different shells out there, but the interesting thing is that they store a lot of common functions. So what I want to do right now is return to Windows and work with the Windows command shell to get a sense of how these shells work. Now, before we get started, I need to warn you about one thing. You are about to learn some really, really powerful commands, and these are commands that could literally wipe your hard drive and that could just wreak havoc.
So one of the things that pretty much all shells have in common is the concept that you can only do certain commands as the “super user,” “administrator,” or whatever you want to call it. Now, different operating systems have different ways to protect you. Let’s watch the Windows way as I load that command shell. So I’m going to type CMD again, but this time I’m not just going to click on it; I’m going to right click. And this time I’m going to tell you to run. As an administrator, I can now run any of the literally thousands of extremely powerful commands right now. So if you’re in a command shell, you need to be careful about what you’re doing. And that’s what all these episodes are all about. Alright, let’s get in here.Let’s do some CLI. You ready? Okay, me too. Alright, first of all, I’m going to just type a command. Now this command I want to show you right now is called Dir. So I type “Dir” and I hit enter. Holy shamole. Look at all this stuff. So what we’re looking at here, and I’m going to scroll up a little bit, is the date and time that these files were created, how big they are in bytes, and the name of the file. And you see this right here? It says Dir. That’s not a file; that’s a folder. Back in the old days, we never called anything a folder. We called them all directories.
The terms “directory” and “folder” are exactly the same, and I’m going to interchange them like crazy, so you’ll be ready for that. All right, back to our dir command. Now, you can see that I can scroll up and down, but if anything changes, I’m going to have to type the command again. So let’s type the dir command again, except this time I’m going to put something on the end. Do you see that? That’s a little slash p. A switch is anything you put at the end of a command in a command line. There are zillions of switches for zillions of different commands. If it’s on the end, it’s a switch. So this time, what it’s going to do is show me all this stuff one page at a time. Now, this little dir command is pretty indicative of the gazillions of commands we use at the command line. None of them are really in plain English. And you have to learn this stuff. And this series is the best place to get started. So if you learn about something, how do you remind yourself? For example, when Mike typed Dir, what switch did he use to show one page at a time? Well, let me show you a really important switch in the Windows world. Ready? You see that slash question mark? What’s that going to do? It’s going to say, “Teach me a little bit about the dir command.” So it will go through and show you. Look at all these different switches I can use, so it’s very, very helpful to be able to remember that slash question mark.
Now, equally, you can do something like this: Just type in “help” and then the command you’re interested in, and you basically get the exact same output for the exam. Make sure that you remember the slash question mark switch, then help, and then the name of the command. Nobody has these things completely memorized. I’ve been working on this particular type of commandline now for, okay, a long time, and I still have to go into Help all the time. It’s normal, and it’s okay. All right, so let’s go and type CLS and get our screen cleared. Now if you take a look up here, you’ll see it says “C Windows System 32,” so this prompt actually points at a particular location; the prompt itself is looking in a very specific folder, and as we look in different folders, this will actually change. So these are the basics of a command line using Windows. Let’s do it again, except this time I want to do it in Linux. You’re going to see that it’s basically the same with a few little changes. So, in Linux, I’m running a little thing called a bash shell. Now a couple of things take place. Number one, you can’t open shells as an administrator like we do in Windows. Instead, what we do is use the command sudo.
If I want to do anything, I’m going to type sudo and then whatever command I want. So the Linux equivalent of Dir is LS, and I’m going to have to type in my password again, and then it works. So be comfortable with this difference. Remember, in Windows, you’re going to start a shell as an administrator, and then you can do anything you want. In Linux, you just start up a shell, and then anytime you do a command that you’re worried about, just type sudo at the front. I didn’t have to type sudo with that LS command. It would chase after anyone. But that’s basically the nomenclature. By the way, if you want to, you can open up a command shell in Linux and then just type Su, hit Enter, and then type in a username and password for the super user, and you don’t have to type sudo anymore. However, the Linux powers think that’s a really bad idea. We all believe in the power of pseudo, and I think it’s a good idea too. Anyway, back to the terminal. So as we take a look at this, we’ll type LS by itself because we don’t have to type sudo, and you’ll see that in this particular shell, it marks folders in blue and files in white, and that’s just the way this one’s set up by default. In fact, if you want to, you can change it. If you want to clear the screen, type “Clear,” don’t type “CLS,” and that’ll clear the screen for you. So the whole idea of switches also comes into play in a Linux environment.
Let’s go ahead and type that LS command, except this time I’m going to put a little twist on it. So now I’m going to type LS, but in this case, I’m going to type LS minus L. So I put this little switch on here, and what this does is show me a little bit more information. So it shows me all of the file and folder permissions for each one of these. It shows us who the actual owner is and who the group is. It shows the size and then the date and time, as well as the name. Switches are just as important in the Linux world as they are in the Windows world, so get comfortable with them. Now, you’ll notice that when I typed “switch,” I used a dash and not a slash. There is no guarantee, even in the Windows world. Sometimes switches use a dash. Although I can’t say I’ve ever seen a slash used in the Linux world, so don’t count on that one. All right, now the big challenge we have is: how do we use these tools? Is there a slash or question mark? No, but there’s something very close, and it’s called looking at the manual. Let me show you. If you want information on how to use a command, just type “man” and then the name of the command you’re interested in. This will bring up the manual for this particular command. So it shows you all of these little switches that we can put in with the LS command and Q to quit, I believe it says. There we go, and we’re right back in our shell. The last thing I want to mention is that I’ve been working in a shell. How do I turn it off? Well, you can usually type something like “exit” or “quit,” but on all operating systems, just close the window and you’ll be absolutely fine. Okay, these are just some of the basic concepts of how these different command-line interfaces work. Keep in mind that there are many shell options available, and we go over them in other episodes. Remember, there’s always help somewhere.
2. Navigating the CLI
If you’re going to be working at a command prompt, well, you better get comfortable navigating around your system. So in this episode, what I want to do is just show you how to move around your computer. And let’s go ahead and start with Windows. The first thing I want you to notice is that when I started this command prompt, I did not start it with administrator print privileges. So it puts me in what we call our home directory. I’m logged in as Michael M.
Now if I do a dir in here, you’re going to see all of these different folders. There’s my desktop, my documents, and my downloads. This is all my stuff. Every operating system has some kind of home directory where individual users go to. We like to keep users in their home directories because we can go a lot deeper than this, and we’re about to. And that’s where some of the scary stuff is. There will be dragons. So let’s go ahead and take a look at some dragons here in Windows. The first command I’m going to teach you is CD backslash, just like that. Now what’s happened here? You can see the prompt has changed. We’re no longer in the user’s MichaelM folder. We’re now in what’s known as the root directory. So if I type the directory in here, you’re going to see the core files for the operating system.
So here are the programme files (program files 86), the actual users, and Windows. These are all the absolutely critical files. You want to take this system out. Just delete that Windows folder right there. It’s not that easy, but you could. So that CD command is really important. CD stands for “change directory.” So if you take a look, I’ve typed “Dir.” I just typed it again, and you can see I’ve got a bunch of directories in here. So here’s a directory called Timmy. If I want to go into that directory, I just type in CD. And in fact, if you want to, you don’t even have to put a space in there. CD Timmy. I hit enter, and you’ll now see that I’m in the Timmy folder. The actual prompt shows that. And if I were Dir, we should see something different. And this is basically an empty folder. So if you take a look here, what you’ll see is a dot and a double dot. dot basically says where I am right now. This is me. A double dot represents the breadcrumbs that connect this folder to the next folder upstream. We can actually use these to our advantage. Let me show you. So we can see I’m in the tummy folder. To advance one folder in the chain, I simply type dot CDSpace.
Now Timmy is connected to the root directory, and we can use this as a shortcut to go up and down. Now let’s play with this a little bit more. I see another folder up there called Windows. Here, I’ll do Dir again in case you don’t believe me. So here’s a folder called Windows. So I can type CD, slash Windows, and I can get to the Windows folder. Now, if I type Dir here, there will be a lot, but only a few. You’ll see there are a lot of folders in here. So here’s one folder called “Temp.” Now for me to get into that, if I ever want to go down into the chain a little bit, you don’t use aslashes at all; you just type CD space and then the name of the folder, and that will get you in there. There are a lot of rule sets in here that are really shortcuts that I’m showing you. Let me show you the CD command with the long hand. Not that anybody does this, but it will help clarify a couple of the commands we just gave. So right now, if you look at this prompt, it says “C Windows temp.” If I want to get to C Windows, the official format is to type “c:” and then see what the prompt would look like if I was there. Now we don’t type in that greater than sign or flashing cursor, but I’m going to type CD space, C Windows now because we know there’s a shortcut using the double dot, and we can cheat and go. And that brings us up to date. In fact, if we want to, we can go all the way here, and we’re back at the root directory. So let us go through this process once more. So this time I see there’s a folder called “Users.” So I’m off to CD. Now, if I were doing it the official way, I would type “CDSpace, C users.” Oh, there are a couple of minor cheats we can use now. So let me get back to the root directory. Because I’m already in the C drive, I’m going to type CD.
I don’t have to type C, so I could type CD users, and that’ll get me up one.And let’s take a look at what’s in here. We see there’s a folder called Michael M. So watch this. I’m going to go back to the root directory, and in one jump, I’m going to go all the way to Users. Michael M. So I type CD space using the official criteria. In fact, let’s skip the sequel because we already know we don’t have to do that. so I’m going to type in users. I’m going to type in Michael, M, and Viola. I get there in one big shot. So the trick to the CD command is to remember that you can do a lot of shortcuts officially. You’re supposed to type “cd space” and whatever path it is you want to go to. And that works; there’s no problem with that. But we can use shortcuts. For example, dump the COON with a space to go down one in the tree and your double dots to go up one. And the big one is that a CD backslash will always get you back to the root directory.
The first few times you play with this, you’re going to get lost, and that’s okay. Simply type CD backslash to get to the root directory, then start CD after you’ve worked your way around a bit. And remember, any time you change directories, type dir because you want to see the contents of where you now are. So this is great for marching around on the same drive, but we have other drives on this computer. For example, I’ve got a D drive. If we want to get to another drive letter, just type the drive letter. So to get to the D drive, I just type “D.” I can type “dir” in here; there’s not very much in there, but I’m now on the D drive. Be careful with this. People will begin to say, “Oh, I need to copy the CD to the D drive.” No, no, no. Get to the drive letter you want to be on, then use your CD commands to navigate to the folder you want. So watch this; this could be interesting. I was already in the Closers section when I typed the D colon, with Michael M still visible on the screen. You see that? Now if I type “C” to get back to the CD, look where it puts me. So it’s always going to put you back in the folder you were in when you originally left that particular drive letter. So just be careful with that.
Everyone thinks it’s always going to get dumped in the root directory, like it’s some kind of hallway with a front door. You’ll now return to whatever directory you were in before. Also keep in mind that I’ve got a lot of drive letters here. Watch this. If I type one like “x,” it just says the system cannot find the drives specified. It’s nice when you’re in a graphical user environment and you’re running things like File Explorer and Windows because you can see all the different drives when you’re in a command prompt. Sometimes you don’t keep track of all the drive letters, and it’s very common to just type in something. It’s not going to hurt anything at all. It just says there’s nowhere to go there. And you’re like, “Oh, okay, good enough.” Now I want to do it all over again, but this time with Linux. There are a few differences, particularly with Linux: Linux does not use drive letters. Unix has a root directory, but it’s just a hash of everything, including extra drives and CDs. They just get folders mounted on this great slash.
So, let’s try it again in Linux. But remember, we don’t have drive letters this time. We just mount all these volumes as folders. So now I’m back in Linux. Now the first thing I want you to notice is that I’ve already got a CDROM mounted on here, which we’re going to go over to and take a look at in a moment. But first, let’s do some basic navigation. First of all, in Linux, and also in Macs, by the way, because Linux and Macs are virtually identical in this part, we still use the CD command. However, things change a little bit. So let me do an LS. So we can see what’s in here, and we can see in blue that I have a number of folders. So in order for me to get to, for example, the desktop there, I’m going to type CD. And folks, Linux cares about capitalization, so we have to match the capitalization exactly. So d’esk capital. Now let me show you another fun little trick. By the way, this also works in Windows. If I hit tab, you’ll see that the only thing in here that starts with desk is that desktop, right? There are examples on the desktop, but everything begins with examples. If I hit tab, it automatically fills it in. Now the other thing I want you to take a look at is the slash. We’re in a Windows environment, so we use a backslash. In the Unix/Linux environment, we use a forward slash and just hit Enter. Then we do an LS. I don’t have much in there, so it’s kind of blank, but we still use the CD command. But things change a little bit.
So I’m going to show you a really handy command. What I want you to do is type “CD-space” and then a tilde. This will always return you to your home directory. So do it. LS, and there it is. See, I told you. They, like everyone else, have home directories on Linux and Mac. However, the root directory looks a lot different in this world. Let me show you. So we type CDSpace, a forward slash, and that puts you in the root directory. Now it’s really hard to tell because the prompt in Linux, or at least by default in the bash shell of Linux, doesn’t really change much. But if you look really closely there, you’ll see that tilde. That tilde says we were in the home directory when we typed this, and now it just says a little slash. So if you actually ever want to see where you are in Linux, just type PWD. PWD just shows you what directory you’re in, and you can see it’s just a slash. That’s because we’re in the root directory. If we type LS, we are looking at the critical system files of the Linux system itself. So generally, it’s a good idea to stay out of these core files unless you have a specific reason to be there. And regular users should pretty much never be in here. They should be staying in their home directories. Now let’s take a look at this screen one more time, and you can see I’ve got this CDROM mounted. Now, it’s nice in the GUI, but I want to show you where it is in the Linux environment. So this is going to take a couple of clicks for us to get here, and we could practise with the CD command as we go. So first of all, as we take a look at this absolute route, what we’re looking for is a folder called Home. There it is, right there. So I’m going to use my CD command in this case. Taking a step down For an LS, it works exactly like it does in Windows. So we can see there’s not much in here. Be careful. Linux distributions do all of this stuff differently. So you see Home, and you’re like, “Oh, we’re in Mike’s home directory.” Not in this particular version of Linux, Ubuntu.
This is a separate thing that allows different kinds of media to show up differently. That’s what it boils down to. Does CDOT operate in the same manner? So I’m going to CD into media. As a result, CD-space media. Allow me to do an LS in here. Now we’re looking at all of Mike’s different volumes and everything. So now I’m going to go into Mike and let’s do another LS. And if you look right now, you can see, let me be clear, you see the name. cccoma, cccoma, cccoma. Do you see that? So, thanks to tab, I could actually look at the contents if I wanted to. That’s a lot of typing. Why don’t we CD into that, fella? There we go. And if we do an LS, that’s the actual file that we see in the optical medium. In fact, if I open them upright here, you can compare them. So we have autorun, boot, boot, boot MGR, boot, MGR. The files are the same. So navigation is a critical part of moving around our systems. When you’re at a command line, keep in mind that a lot of these commands, especially between Windows, Mac, and Linux, are very, very similar, and that CD is a great example. The big difference is that in the Windows world, we do a backslash, and in the Unix/Linux world, we do a forward slash.
3. 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 discs 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 them laying all over your computer. So remember not only that we’re going to do this by hand in here where we’re typing commands, but also that everything you’re learning will apply to everything in other episodes. The command line can be integrated into scripts, and that’s where the beauty really kicks in for the command line. So you’ll need to learn how to create directories, folders, and delete them using the command line. Let’s do it.
All right, so here I am at a D drive, and let me type D IR. And you can see right now that all it has are 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 it 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’ll type MDspacemic, hit enter, and 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 when 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’ve got to type Dir. I got to see it. Mike is standing right there. Now that we’re 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 already called Mike already.What I’d like to do now is create a new directory called Capital Mike. Let’s watch So Dir one more time. We see that Mike is there, right? Let me clear the screen. So I’m going to do MD capital. 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 microphone directory. In Linux, I could have a capital M, a lowercase M, or just a capital I in Mic, but in Windows, it doesn’t matter. Oh, by the way, did you notice something? You have received an error. An error popped up on the screen. Oh, there was an error. No, you didn’t. You have useful information. Yeah, you made a mistake. But that’s the beauty of a command line. You see a mistake; you’re like, “nothing blew up.” I don’t see any smoke. We’re in good shape. I love angels 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 quick check 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 on CD. Mike. There it is. I typed Dir; I’m inside the Mic folder. Now, if I want, I can create a folder within a folder. So make a directory. Mike again: there’s nothing wrong with having multiple Mic 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. I got the idea. All right, now I’m going to go ahead, and now what I want to do is delete a folder. So if I type Dir one more time, there’s the Mic 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, 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 Mic folder, and it’s gone. So let mNow watch this. Do you see that folder called “VMs”?And by the way, this is all the virtual machinery I use in this course. Let’s just go ahead and wipe them all out. You c. Now watOh, 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 a good time. Let’s try it again in Linux. So now that I’m in Linux, let me do a quickLS to 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 Nkdir. To make things more interesting, I’m going to insert a 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. TADA, 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; 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, in order to get rid of capital, Mike, I’m going to type R m dir.I’m going to type a capital M. I hit that tab key because it’s the only folder in here that starts with a capital M, and it’s gone. Yeah, we’re on a roll. I’ll press the up arrow key, change that capital M to a lowercase M, and the folders will be gone. 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 video. Bye.
4. Working with Files
We are continually working with files from a command prompt, doing anything from things like moving big piles of videos to dealing with log files or all kinds of stuff like that. We’re constantly in a world where we are copying files, moving files, and deleting files. And in this episode, I want to show you how to do some of that. On top of that, I’m throwing in one little extra, but I’ll save that until we get to Linux. Okay? So what I want to do right now is talk about deleting files. So if we take a look at my Windows system, we’ll see when I type “DIR” that I’ve got a bunch of files here.
So to delete a file, all you have to do is type del. By the way, erasing also works, but del is what everybody uses. And then you type in the name of the file. I’m going to delete that Micron JPEG. You hit enter, and it’s gone. See? No more microphone. One JPEG. There’s a microphone for JPEG. Don’t confuse them. OK? Isn’t that easy? Yeah, well, it is. So, number one, you’ll notice that it didn’t say anything. We just said delete, and it said okay. There wasn’t, like, are you sure? Do you want me to check? This is not going into a recycle bin. It’s gone. So you need to be very careful when you’re deleting from a command prompt. Now, the challenge we run into is that it would take forever to delete all these files individually. So instead, we use a wildcard. So let me show you how wildcards work. In this particular case, I want to delete all the files that have the extension TXT. So I’m going to type del, but this time I’m going to type in an asterisk. Asterisks mean I don’t care, and I’m going to type dot TXT.
So let’s look at what we just typed delete.I don’t mind what the first name is as long as it ends in TXT. So I hit enter, and let’s type “dirto” to see the results of our work. TADA. All those files are gone. The only other thing I want to show you at the Elite is the most powerful wildcard of all: star asterisk. Splat. Splat. It’s got a million names, but it works the same way. Now, Grant, I’ve only got a couple of files in here, but it’ll still work. So this time I’m going to type del asterisk asterisk star splat. Splat. Now remember, it didn’t give us an “are you sure?” Right? This is the one time it will, and we hit Y for yes, type dir, and absolutely everything is gone. There are actually more wildcards in the Windows environment than just Asterisk. But the asterisk is the big one and the one you’re going to see on the exam, so be comfortable with it. All right, so all we’ve done up to this point is delete. What I want to do now is let me grab those files, bring them back, and this time let’s do some copying. Okie dokey. Let’s take a look. And now all my files are back. And now I’ve got to do something with them. Let’s pretend for a moment that these are really critical files. And what I want to do is put the disc on a thumb drive as a quick backup. Now again, in a Gui environment, yes, we could drag them over. But this is going to be part of a complicated script file that cleans up all this stuff after I do a bunch of other things. So we want to make this run from the command line. So what we’re going to do is copy. Now, copying is pretty simple, but remember, Mike, super duper fancy five steps on how to copy. So let’s make sure we know what we’re going to do here.
I want to copy all of those files over to my thumb drive. And my thumb drive is actually the K drive on this particular system. So I just want to copy them over to that thumb drive. So here we go. You ready, Mike’s?Five-step procedure Number one, get to the directory where the files you want to copy are located. So I’m there. I’m here on the D drive. This is where the files are. So step one is done. Step two: type the word “copy” in a space. That one’s pretty easy. Step three: type the name of the file you want to copy and a space. In this case, I just want to copy one file. Number four: type the path of where you want it to go to.In this case, I’m just dumping them on my K drive. I don’t have any folders on my K drive, but if I did have a folder like Fred, I could do this. But in this case, there are no folders on my K drive. I’m just going to type it like this: That’s step four. And then, at number five, I hit enter, and one file copied. So, whenever you copy, the first thing you should do is go over to the destination to ensure that it arrived. And there he is. Fantastic. Let me delete that real quick and go back to the D drive. Let me clear this mess up. So that’s a basic copy. Now there’s also a move command. The only difference between a move command and a copy command is that instead of typing copy, you type movies. The only functional difference is that the copy command makes a copy of the original and then deletes it. So make sure you’re comfortable with both of those. The actual nomenclature is exactly the same. I don’t want to run through a move. Once you see copy, moving will make sense.
Now let’s go ahead and take a look one more time. I obtained all of these files. Now. This time I want to copy all of the JPEGs over to the K drive, so I’m in the right directory, I type “copy” with a space, and I type the file name, except this time I’m going to use a wildcard and a space. I type the destination where I want it to go, and I hit enter. Fantastic, right? How easy is this? Well, it is nightmarishly easy to mess this stuff up, so I’m going to intentionally make a mistake. Watch what happens when I just make one tiny typo in the copy command. So this time I’m just going to hit the uparrow key, so I just bring the command back, and what I’m going to do this time is, let’s just say I accidentally typed a semicolon instead of a colon. It looks like it worked, right? Yeah, we’ll look really close. How many files have been copied? One because what we just did was take those three files, squash them together, and make them into one file called K without an extension. That’s why, whenever you copy, you really need to take the time to go over to the destination, look at everything, and make sure it’s there in good order. I actually made a typo like this in a big script file that was pulling down hundreds of thousands of system logs for computers all over the country for a large enterprise, and you can’t even imagine the mess I made just because of one tiny typo, so be careful with the copymovecommand. Now if I want to copy everything, I can use good old Splat Slat Star, and it will copy everything in one big shot. Now notice there’s a couple of files that we’ve already moved over there: Fred, TXT, Mike, one JPEG, and then the big mess called K. We’re not going to worry about him; just say yes, yes, and everyone will be fine.
So that’s the other nice thing about the copy or move command: if it sees a file with that name already there, it’s going to give you a little warning and say, “Do you want me to overwrite them?” I could have said yes, which I did; I could say no; or I could have said yes just for everybody by hitting a for all. So that’s the copy and move command. Now what I want to do is let’s do this all over again, except this time in Linux. You’re going to notice it’s very similar. However, there are going to be a couple of small functional differences. Yeah, let me show you. Take a look at my Linux desktop. I’ve got all kinds of mess on here. Look at all these files that are piling up. So one of the things I want to be able to do is actually delete a file. So to delete a file from the command prompt within Linux, all I need to do is type RM and then the name of the file. So I’ll delete Mike’s one ODT, and it’ll be gone. Now if I want to use a wild card, I can. Now that we don’t really use a star-dot-star within Linux itself, we can put an asterisk after or before a letter. So, for example, if I wanted to, I could doM stricken, and that would delete all of these files. But I need these files. I don’t want to actually delete them. that command, right? There would be no issue. I could also type in RM, and that would wipe out anything that’s sitting on my desktop, so you want to be careful with that. However, to copy it, it works very similarly to what we saw in the Windows environment. You want to start off in the directory where you want to copy from.
And here I am on the desktop. Except now we use the CP command before we get much further. Keep. In mind, if you want to move within a Linux environment, just replace that CP with MV, and that will move instead of just copying them. Let’s keep going. Now I’d like to put all of this together. You see, I’ve got a folder in here called Gather. And this is actually very similar to my real desktop at my office. I put so much junk on here that I will dump it all into a special folder on my desktop called Gather, and then I will look at them at a very specific time and then just try to sort through them on my own. I just don’t like it messing things up. So I’m going to go ahead and copy, and now this time, I’m going to go ahead and copy everything. So I’m going to copy m star.M star. So keep in mind that capitalization is still important here, as is only the name. of the folder I want to take it to. Let’s see if I’ve done it right. Yay! My files have been copied perfectly. When you’re working with files, I’ve given you some really powerful and some really dangerous commands. Right? Understand that if you delete something, it is most likely permanent here. It’s not like using your beautiful little trashcan or whatever you have within your GUI. Also keep in mind that you need to always go to the destination of whatever you’ve done to make sure the stuff got there in good order, or else you could end up potentially finding a huge mess.
5. Working with Drives
You can do some absolutely terrifyingly powerful things to hard drives from a command-line interface. And in this episode, I’m going to scare the bejeezus out of you because we’ve got some really cool tools. The first one I want to talk about is probably the easiest, and that’s the good old format. So, if you look up on the screen here, on the righthand side, I have Disk Management running. And you’ll see I’ve got a drive here that I’ve got set up as the E-drive. It’s not formatted. I’ve gone ahead and partitioned it as one bigE drive, but I have to format it. Over here, I’ve got a command prompt open, indicating that I’m running as an administrator because this format command won’t do this unless you are an administrator. So I’m going to type in “Format” and then the drive that I want to format. And now I want to do the file system.
So you know what? I don’t remember how to do that. So watch what I’m going to do. I’m going to type in “Help Format” and I’m going to scroll through here. Somewhere in here is the file system. There it is, right at the top. So I type in a slash (/) and then the one I want to do, which is going to be NTFS. Perfect. Got it. Let’s hit enter. Do I really want to do this? You know what? I don’t, because it’s going to take forever. So let’s go check on that Help again. I’m hitting the up arrow key, and let’s see what the quick format is. Q. Now we’re talking. So watch this. just hitting my up arrow key. Look at that. I’ve got a couple of switches in there. So let’s go ahead and hit Enter. Do I really want to do this? Yes, I do. Do I want to give it a volume label? I don’t want to. And I’ve used a tiny drive here as an example, so it happened very quickly. So that’s the format in a nutshell. You need to be really careful with this tool. If you are set up with administrative privileges, you could format your C drive and wipe out your Windows in one fell swoop.
So make sure you know what you’re formatting when you’re using this tool. Most of the time when we’re formatting from the command line, we’ve got a bunch of thumb drives we need to format. We have a small file that will be formatted and will contain a number of files that we require. So be careful when you use it. All right, so that’s the format. Now the other one I wantto talk about is error correction. What we’re going to be taking a look at right now is the classic check disc (CHK DSK). We can now do the same thing graphically by going into a drive’s properties and selecting Error correction. But we can also do this from a command prompt. To do error correction from the command line, all you have to type in is “chkdsk.” Now, if you type it by itself, it’s going to go through and check the drive, and it’s going to check it really well. It looks like everything is pretty good. Three, two, one. And it is very happy when you type CHKDSK by itself; it just looks at the existing file table, and anything that’s marked as bad, it’s going to skip over that. And anything that’s marked as good is just going to say, “Yeah, it’s good.” Well, the problem is, when I do error correction, I am worried that certain blocks have gone bad since the last time I did this. And that’s the whole goal behind this. So checking this by itself really isn’t very helpful. What’s more important to me is that it actually fixes it. Remember, Check says this doesn’t really fix hard drives.
It just puts orange cones around bad blocks. So let’s do it again, except we’re going to have to add a switch. So this time I’m going to type in CheckDisk, but this time I’m going to add the slash F switch, which means actually go and fix things, and I’m going to let that run. Now, you’ll notice that it’s saying Check Disk cannot run because the volume is in use by another process. And it says, “You want me to check this next time you restart?” And we always say, “Yes, the next time I boot this system, it’s going to go ahead and run the check disc and check all of my blocks to make sure that they’re good.” Then it’ll go ahead and boot into Windows normally. So that’s a pretty common way to run Check Disk and the only way to do error correction from the command line. Now, Check Disk is cool, but if you want to see some really powerful tools, you need to take a look at the tag team of System File Checker and DISM. And I never remember what all these acronyms stand for. That’s a clue. They never test you on what they mean on the exam, either. So I want to be your pal. Put it up on this. Ah, there we go. Thank you very much. Anyway, the idea between System File Checker and DISM is to take a look at your system store, the backup copies of your critical system files, and to check them against the working copy. Always start with System File Checker.
You run System File Checker, and it’s going to take a look at your backup store and compare your working files to those. And if it finds any bad ones, it will examine them or, depending on how you run it, can actually fix them. In general, we run it to see if it fixes itself. However, there are situations where even your backup store can be corrupted, and that’s where DISM comes into play. So we’re going to run SFC, take a look, see how that goes, and then run DISM. You always do it in that order. Let’s start with the system file checker. To run System File Checker, we just type in “SFC,” but that is almost completely useless. So we’re going to go ahead and do what’s called “Scan Now.” SFC is now running and looking at all my critical system files and comparing them to the backup store. If it finds any bad copies, it will literally grab one from the store and write it over in real time. This is going to take a few minutes, so I’m going to have to wait for a reboot. Now, while we’re waiting, there is one other thing I want to mention. You can run Scan Now in another mode called Verify Only, and all that does is run the same thing.
And if it finds any bad system files, it’ll simply warn you that they’re there. A lot of technicians like to run that because they want some kind of evidence that there are problems with certain files, whereas Scan Now will simply overwrite them and fix them. It does show up on the screen, but most people don’t sit there and watch it. If you run into a problem with SFC and have it nicely documented so you can see it, it will also store it in a log file. If necessary. There is an event viewer visible. The standard rule is to then run DISM. DISM is built into every copy of Windows, and all it’s going to do is go online to Microsoft and find the version of Windows you’re running. Remember, just because I got ten, there are a lot of iterations in there, and we’ll compare my system store to what Microsoft knows and likes. So this guy kind of guards the guards, so let’s go ahead and run DISM. So DISM requires a number of complex switches. So I’m just going to type these in, and you can follow Mike as he goes. So we run the command. Then we say, check the online store at Microsoft. And then we say, “Go ahead and look at our actual store on our drive.” And then, if you find any problems, fix them. Wait until you have DISM installed before running SFC.
Go online, check with Microsoft for the versions of all the critical files, and check my store against them. If this runs less than 20 minutes, you’re extremely lucky. but we love it. It’s an incredibly powerful tool, and it literally goes to the source to verify the quality of all of our system files. Now the trick is running SFC and DISM as a pair. Always start with SFC scannow. Then, if it finds any errors at all, you go ahead and run DISM. After running DISM, we assume everything’s okay, but we go ahead and run SFC a second time to make sure everything’s happy. Again, you literally cannot have bad system files unless there’s some horrible corruption on your hard drive. By using this methodology, it will fix everything every time, and it’s absolutely amazing. Okay, now the last thing I want to do in this episode is talk about your ability to do anything you want with mass storage from a command line. We can partition, we can format, and we can do anything you want using a tool called Disk Part. Talk about a scary tool.
This is probably the scariest because we can completely wipe any hard drive with it. So you have been warned. Let’s take a look at this part. The best way to demonstrate disparity is to run disc management while I run the commands. So what I’m going to do first here is fire up this part, so it’s D-I-S-K-P-A-R-T. How’s that for easy? Now, this puts you in front of an interactive screen. Notice that we’re not back at a prompt here. It’s asking for demands. So there are a tonne of commands in here. If you type “Help,” you can see all the different types of commands you can run here. So what I’m going to do in this scenario is partition and format this drive right here. So the first thing we always do at this point is list. So right now, I see I have two disks, disc zero and disc one. If I were to select disc zero right now, that would be bad because that’s my bootable. So I’m going to very carefully select disc one. Okay, now I know any commands I’m about to do are going to be done on disc one and not disc zero. So the first thing I want to do is create a primary partition. As a result, I’m going to make a primary partition. Why does Microsoft do it backwards? because they’re Microsoft now. You see, we’ve now created a primary partition. By the way, I could add numbers in here if I wanted to only make it half or something like that.
Okay, now I’d like to go ahead and list so I can see that this is my only partition. So again, I want to emphasise that selecting is really important here because this is how we make sure we’re not doing something to things we don’t want to do things to. But Mike, there’s only one partition. I know it’s an old habit. I stick with it, and it saves me. So I now have the partition, and I want to format it. So let’s just type in the format right here, and then FS equals NTFS. And I want to do it quickly, so I just typed it into Quick, and I’ve now actually formatted it. Now, if you’re looking to your right, you’re like, “Well, you formatted it.” Yeah, but I haven’t given it a drive letter yet. So watch this. And now you’ll see that I now have an Xdrive right here where you can see it. This is just one example of how I can partition and format a drive using disc part.All I did was partition and format. You can delete partitions, wipe drives, stretch, and do all kinds of stuff. You can mount Raid on five partitions. This thing can handle it all. But for a lot of us, just being able to partition and format from a command line can be incredibly convenient.