6. Super Copy Commands
One of the biggest jobs we have to do from the command line is copy stuff. And I’m not talking about copying files. I’m talking about entire directory structures. I’m talking about individual partitions when it comes to copying standard copy commands. Just don’t cut the mustard. And we need some supercopy commands. So what I want to do in this episode is talk about three different types of supercopy commands. Two of them are more for Windows, and one is for Linux. So let’s start with Windows because, hey, I’m a Windows guy. The first one I want to start with is something called “X Copy.” X Copy is the original heavy-lifting copying tool. It dates back to much earlier versions of Windows, and it’s still with the most modern versions of Windows today. Ex Copy is designed to copy not just files but also directories and all kinds of stuff like that. It has extra features that will allow us to do things like verify the data as it’s being copied to ensure a good copy.
So the best thing to do with X Copy is just watch it in action with a little scenario I’ve got right here. So if we take a look over here on my hard drive, you’re going to see I’ve got a lot of DLL files that I need to get backed up someplace. So what I’ve done is I’ve got over here an X drive, and it’s all formatted and ready to go. And I want to move these over in one big chunk. So to do that, I’m just going to run X Copy. So let’s go ahead and do that. As a result, we’ll make X copies. I don’t even have to type this, but it’s good to have it. I’m already in the backup folder. Now, you’ll notice all I have to do is type in the name of the folder. I don’t have to type “star” or anything like that. So X Copy really thinks in terms of folders, and then I say where I want to put it. And then I could put some special extras on here. For example, slash S means copy all subdirectories, if any. I can put a “V,” which means verify each copy as it’s being copied to make sure it’s a good copy. And then there are probably another 30 different switches; here’s one that’s often used: slashH, which means no hidden files. So we’ll hit enter, and we’re going to let that go to town. So if you’ve got to do some heavy lifting, copying X Copy is a great place to start.
However, there is another, and that tool is called Robocopy. Robocopy and X Copy are nearly identical. It saves many of the same switches even.The only difference is that Robocopy is vastly improved to handle more verification and more speed. So what I want to do is go through the same scenario, except this time we’re going to run it with Robocopy. So we’re going to type “robocopy.” Now, I could be in the backup folder if I wanted to and skip this step. But in this particular scenario, I’m actually in the root directory, you see. So I’ll type in the name of the folder, and then I’m going to type my destination, and you’re going to see a lot of these switches are similar to X Copy. In fact, copying all subdirectories is identical to Ex.Copy. Another really popular one is that I don’t want to copy any hidden files. Now this is a different switch than the one we just saw on X Copy, but it should be in good shape, and when we hit Enter, Robocopy is going to be up and running. The cool thing about Robocopy, and X Copy does this as well, is that they are network aware.
So let’s say I’ve got a bunch of virtual machines on my D drive and I want to copy them over to a shared folder on another computer. What I can do—let’s just use Robocopy as an example—is With Robocopy, I can type a command that looks something like this. So I can type in Robocopy where the source of my files is, and then for my destination, notice that I can actually use a UNC value. So this UNC value points to a shared folder that is actually on my network. Notice how I put that in quotation marks. That’s pretty standard nomenclature for Windows. And this type of command will allow me to do all of my copies across the network as though it were just another drive. So these have some really big features that make them attractive when you have to do a lot of big copying. Well, that’s fun. But now what I want to do is move into the big, wonderful world of Linux. In the Linux world, the heavy lifting champion is the good old DD command.
So DD is a little bit different. DD is a bit-by-bit copier, and he lives his best life when he’s copying entire partitions. So he can even be used to make image files. But before I can show you DD, we need to talk about the nomenclature of how Linux names partitions. Let’s take a look right here. So what I’ve got here is a Linux system that has two drives and optical media. So this is my boot drive right here. Now, if you take a look—and you have to look very closely—you see where it says “Dev SDA One.” So that is the actual way that Linux recognises these individual drives, which are each one big partition. So this one’s SDA, and then this one’s SDB. And if you’re actually interested, optical media is going to be like SR Zero. So if we know what our partitions are named, we can actually use this to put the DD into action. So let’s make this one pretty simple. So what I’m going to do is copy everything from SDA to SDB. So to do that, we just type in “DD” and then a space, and then “if” is our source. So, if is equal to devsda and our destination is shown as of, then it is dev SDB in this case. Now, if that was the only thing that DD could do, it would be amazing.
But it could do a lot more. For example, instead of copying from one partition to another, we can just make an image file. So take a look at this command. Now you’ll see that we have a source. But notice where the image is. In this particular example, the destination is a file called backup.IMG. So it’s going to take everything in that partition and make a bit-by-bit image file of it that we could then use for backup. We can even make bootable media from this. Now, if that was all that DD could do, that would be great. But wait, there’s more. A lot of times, if you really want to wipe a drive, DD can be an amazing tool. So what I want you to do is take a look at this particular command. Notice the use of the word “zero” in the source. What it’s doing is not copying anything but a preset bunch of zeros. When you put the zero in like that, that means just write zeros to this destination. So we’ve erased everything on this destination partition except zeros. Look, if you’re going to be working at the command line, odds are good you’re going to have to do some heavy lifting when it comes to moving around folders and files. Make use of these powerful tools to make your heavy lifting life much easier.
7. Advanced Windows Command Line
The CompTIA exam lists a few more command-line interface commands that, while unrelated, are very, very important. So I kind of just threw them all together and called them advanced Windows commands. So let’s go through all of these. The first one I want to talk about is shutdown. Yep, you can shut your computer down from the command-line interface just by using the shutdown command. It is not common to just run shutdown by itself because it has a lot of really interesting switches.
For example, a slash S means “just shut it down.” However, R means go ahead and shut down and restart the system. There are a bunch of other shutdown options. For example, you can schedule when you want the shutdown to take place. You can say it well: I want everybody to log off first. So there are a lot of features to the shutdown command. But honestly, most of the time if I’m running a shutdown, it’s because I’ve got a problem, and I’m usually doing shutdown space to just shut her down. So be aware that the shutdown command can really shut your system down quickly if you need it to. Now, the next one I want to talk about is actually pretty cool. And this is task creation and task elimination. Task lists all of the processes that are running on your system. It will display their name, their Process ID, and other information, and then Task Kill, as you might guess, will allow us to shut down any of these processes either by their name or their Process ID number.
So let’s do both. A task list is pretty easy. Just type in “task list” as one word, and it’s going to give you a big list of all the running processes on your system right now. So what I want to do is turn something off. So let’s go through and see if we can find something fun. Okay, now look right here. Do you see? It says Skype app EXE, and that’s the Process ID number 27 four.And if I scroll this up, you’ll be able to see that. So it’s the name of the file, processID. Who’s using this type of session? Is it a service? Is it an application that I call Console? How much memory is it using? that whole idea. So let’s find out one more time. OK, so here it is. Skype.exe has a process ID of 27 four.Now that I know that, I can now turn to Task Kill. Most of the time when I’m using Task Kill, I like to use the Process ID to kill something, although you can use the name as well. So let’s do a little killing. So, if we remember correctly, it’s Skypeapp Exe with a ProcessID of 27. So I can type in “Task Kill.” Now, this is a good place to use Help because it shows some fairly interesting options. First of all, look at here; it says Task Kill with the Process ID, and then you just type in the number. However, if you want to, you can actually see an example of a notepad that I can use.
So let’s just go ahead and turn this off using Process ID, and it’s dead. Jim, a lot of times when you’re running scripts, in particular, these types of tools, especially if you’re trying to turn something off to do an installation in a script or something like that, can be absolutely handy. Okay, the third pair I want to talk about is something called GPU Update and GP Result. In order to make sure we understand what these guys do, what I want to talk about is something called a group policy. Here I’ve got my own little computer, which I run every day, and I’ve got some local security policies set up. In particular, I have a local policy that says we don’t care about complex passwords, so no complex passwords for us. However, this computer is a member of a domain, and he is connected to a domain controller that is controlling the domain that I’m a member of. Inside this domain controller, they have their own security policies, which are called group policies. It’s really just about exactly the same thing, except that these have much more complex policies. They have pretty much everything I’ve got, plus a lot more, and they have set up a policy that says we require complex passwords.
The issue is that there is no active way for a change made up here to quickly propagate down to all of the individual systems. So we’ve got to sit there and run something over here that says, “Have you made any changes, sir?” And then it will update our policy on our machine. If you’re on a domain and you have a group policy that is different than your local security policy, well, tough bananas, it will override it. And this is where these tools come into play. We’re going to use GPU Update to query our domain controller and see if anything’s been changed. Then we look at GP Results to see what changes have occurred. So let’s start running them. So first we’ll just run GPU Update, and he’s going to go out to the server and just update this policy. It’s pretty straightforward, although it can take a moment before we actually get the answer we want. So let’s see what happens. Fantastic. Now, the problem here is that it said it was successful, but how do you know that? And that’s where you use GP. Result. Now, I need to warn you: the output from GP Result is messy. You’re not going to be quizzed on how to interpret everything, but you should have an overall look and feel where, if you see a question on the exam that says, “What output did this?” you should be able to recognise it as a GP result. It’s a pretty obvious-looking output. So I’m going to run the GP result with that R option. R is actually the smallest output you can generate.
All right, so this is the end result of this. The important one is right here. I’m just doing this as a demonstration. So unfortunately, I don’t have anything updated on my group policy server to make a change here. But here’s where we would see the results and have verification that, for example, a complex password applied would show up right here. You don’t run GPU Update or GPU Result just for fun. It’s not a maintenance tool. You’re running it because somebody on high has said, “We have gone ahead and made some policy changes, and we need them to get down to all the individual client systems.” In fact, we usually don’t even run them manually. What’s happening is that we embed these into scripts so that they’re like, “OK, we’ve got everything updated.” Be sure the scripts run on everybody’s computer at 3:00 a.m., and then we hit a button, and they all run, and we’ve got our job, and we can go home at 5:00 p.m. that afternoon. So these are some very interesting tools, and you will see them both on the exam. In the real world, things take some time, particularly with shutdown. It can be an incredibly handy tool.
8. Advanced Linux Commands
Well, you can’t have an episode covering advanced Windows commands without doing the same thing for my friends over at Linux. And by the way, pretty much all these commands work just fine on a Mac as well. So in this episode, I want to cover a few very assorted advanced commands that you’ll not only see on the exam, but that you’ll use time and time again within the Linux environment. Let’s start off with a big one shutdown. The shutdown command implies that it shuts down your computer. Now, if you type shutdown by itself, you get 1 minute, and if you type shutdown-minus C, that will cancel the shutdown. If you want to shut down and reboot, I’m using the up arrow key. I could just type it like this: “Shut down space minus R,” and that’ll shut it down in 1 minute. It’ll actually reboot the computer, and if you’re really in a hurry, you can type shutdown.
Now, I would like to continue teaching this video, so I am not going to hit Enter, because if I hit Enter on shutdown now, it will shut down and we’ll be done. So let me backspace that out a little bit, clear up the screen, and let’s talk about our next command. Getting applications has long been a major challenge in the Linux environment. Back in the scary old days, you didn’t even get executable programs; you just got source code, which you had to run onboard compilers to compile and go through painful installations, which meant updating text files. And you kids have no idea how lucky you are because certain distributions began to emerge after a while. In essence, in stores where you could grab certain applications and download them, they would automatically install themselves. It was a pretty thing. Now we basically have two camps here: the Debian camp and the Red Hat camp. This is intriguing because some of the objectives on the A say Aptget. That means it’s Debian. So that’s why I’ve been using Ubuntu in these episodes because they actually give us some clues that they’re more into Ubuntu than any of these other distributions.
So AppGet is a great example. App Git is a repository of just about any programme you could think of that can do almost anything you want. To obtain a program, I simply need to be at a command line in Debian-based Linux and execute this command. So I’m on Ubuntu, which is a Debian-based Linux, and I can go ahead and run this. Let me show you how AppGet works. Everything with AppGet starts with sudo aptget update. What’s happening right now is that my onboard repository is being updated so it knows the latest versions of thousands of different applications. You’ll go through this process whenever you install any version of Ubuntu or Debian Linux, and I’ve recently gone through it, so let’s take a look. It’s already pretty much done, so we’re looking good. What I’ve done is update my repository. So it’s amazing. Let’s say I want to use an editor programme called “Joe.” So I’m on my system, and I type in “Joe” because I want to run it, and look what happens. It will actually say it’s not found, but it can be installed. I need you to look really carefully here. It says “pseudo-apt,” not “aptget.” The reality is that AppGet is unfairly deprecated at this point. Apt is used instead of Aptget. However, Aptget will still work 99% of the time, and that’s the actual objective. CompTIA, get up to speed a little bit here, will you? So we’ll do this with App Get for CompTIA’s sake, but normally you just run the Apt command; they work almost exactly the same way. So what I want to do now is install a program; I want to install Joe. It’s actually a really good text editor, so I’m going to do sudo aptget install Joe.
And what’s happening here is that the programme is being downloaded from on high, and it comes down into my system, where it is, well, it’s still installing, but once it’s installed, I’ll be able to run this program. It is incredibly convenient. Now you think to yourself, “Well, Mike, how did you know the name of the programme was Joe?” Well, these are famous programs. If I wanted to, pretty much all of these Ubuntus have some kind of store where it’s done in the exact same way, except it’s done graphically. The important thing is that I can do this from the command line using Aptget. Really? Apt? Okay. The other thing we run into is that we often have to upgrade our software and that be the case.We continue to use the app Get. This time, we’re going to install everything. Cool, let me clear that screen. So this time we’re going to run Aptget. Now I can run an upgrade by itself, and it will upgrade every piece of software on my system. In this case, I just want to do it for Joe, and it will go ahead and upgrade just that one particular application.
So if you want to upgrade everything on your system, just do “App Get Upgrade,” and it will update everything on your system. The last thing that’s going to happen is that sometimes you want to delete a program, and AppGet works fine for that. just as well. In this case, we’re going to use remove. Alright? So let’s type in “pseudo-Apt” to get rid of it. Joe, do you want to continue? Yes. And now Joe is being uninstalled again. Most Linux front ends allow you to do all of this, but if you need to do it from the command line, Aptget, or Apt, is the best tool available. All right, the next thing I want to talk about is something that really happens a lot within Linux, and that is that I’m always wanting to check all of my processes. Now in other episodes we talk about process IDs in a Windows environment, but remember that these are all running on Intel processors, so everybody still has processes whether I’m running on Linux, Windows, or Mac. And if you want to have a look at all your different processes, and especially if you want to turn off a process, you need to be comfortable with the tool called PS. So running PS by itself is kind of boring because all it’s going to show me are any processes that are tied to the user that I’m currently logged in as. So right now I’m logged in as Mike, and pretty much all you’re going to see is the Bash shell that I’m running right now and then the PS programme itself.
But if you look at it, you do get some good information. In particular, you get the process IDs right here and the name of the program. So this by itself is a little bit dull. The PS command comes with lots and lots of amazing flags, but probably the most famous one is PS aux aux. Many people do it because AXU says it doesn’t matter, which means I want to see all of the processes. I don’t care if it’s coming from the system or from other users, and I want a lot of details, so watch what happens when I type Psax. Okay, now we’ve got a mess, but it’s actually really good information. I’m going to scroll up a little bit here. Let’s get up to the top. Here we go. So you can see the process. ID. You can tell what kind of user it is. The root is the system itself. I have a lot of CPU usage. This is just a snapshot at this given moment. TTY means what kind of terminal or monitor it’s using. So what’s really interesting to us more than anything else is what command is actually running it. You can see all these here; when did they actually start? So, between the command and the process, IDwe has a lot of really cool capabilities.
So, for example, if I want to, I’m going to go ahead and start up a program. So let me go in here, and I’m going to start up this little word processing program. So let me minimise that. But we know we’ve got a word processing programme running now, so let’s go ahead and run pSOX one more time. So what I can type is pSOX, and now I’m going to do something called a pipe. Do you see that? That’s a little pipe. What we’re going to do with a pipe is basically say, “Look.” I know normally you would just put your output on the screen, but instead of doing that, I want you to photocopy your output to whatever I type in after the pipe, and this is classically how we use Grep. So I’m going to type in Grep and then whatever string I’m interested in looking for. So in this case, I’m looking for Libre. As a result, it will run the PS aux. It’s going to take all that output and hand it to Grep. Grep is then going to look through that output. Remember that Grep only works with text files. Any line that contains that string, he’s going to bring it out onto the terminal so I can see it. So let’s watch the magic. And here we go. So what’s happened here is that I now see one, two, and three lines. I have three different process IDs.
So this isn’t uncommon. Libre Office is complicated. It’s got three processes; no big deal. So what I want to do now, and this is a big thing we do with pSOX, is let’s do a little more killing. So to do that, we’re going to kill one of these processes using—guess what it’s called? Kill. So watch. So I’m going to type Kill, and then I’ll just type in the process ID, so 13482, and we hit Enter, and we don’t get any output. That’s because it’s dead. So I’m going to go ahead and run PS Ox one more time. And now you’ll see that it actually killed two of the three processes. That’s because there was a dependency in there, and it’s okay that it went ahead and killed two of them. I wish it had killed all three. So that’s a kind of rough idea of some of the programmes that you’re going to be seeing on the A+ exam that are within Linux. But there’s one more thing I’d like to discuss before I leave and come to you. You guys really, really need to get this off of the competencies. We use text editors like crazy when we’re working in a Linux environment. and that’s a good thing. Luckily for us, there are thousands of text editors that work at the command line. I have graphical text editors. They’re amazing. There are zillions of them out there. And yet CompTIA, for some reason, continues to talk about literally the oldest text editor ever invented, VI.
So let me give you at least a quick peek at this absolute disaster of a text editor. To run VI, you just type VI, and I’m going to give it a file name called Junk. And what’s happened now is that I am in a text editor, but don’t you dare think about typing any letters right now. You have to hit the letter I, which will then put you into insert mode, and then you can start typing. Now that seems okay, right? You can even hit Enter to get a carriage return. But other than that, you’re in big trouble. The way you manipulate this text editor dates from the 1970s. In fact, let me show you. I’m going to put a little piece of paper on the screen. Here are some of the commands that you have to do to manipulate stuff in VI. So do you see all these? This is how you move your cursor around within the VI text editor. I’m not sure why people still want to support this, but it’s still out there. Listen, the VI is on the A-plus exam. I’m telling you right now that there are a thousand better text editors. There are programmers out there, and they probably don’t have much of a social life, but they are really, really good at this. God bless them. For the exam, make sure you’re aware that VI is a text editor, and also make sure you’re aware that Mike Myers absolutely hates it. Music you.
9. Command-Line Permissions
You can do a lot with users and permissions from the command line. So in this episode, what I want to do is concentrate first on dealing with permissions, and then I want to talk about things like changing passwords and ownership. So first of all, let’s take a look at changing NTFS permissions using a programme called Icackles. That’s fun to say, isn’t it? Now, if you take a look right here on my drive, you’ll see I’ve got a folder called Timmy, and what I want to do is give the Mikeuser account full control over that Timmy folder. So to do that, we just type in “Icackles” and then the folder or file I want to apply it to, and then I want to grant the user Mike full control. So let’s hit enter.
TADA. Icackles is wildly complicated, and interestingly enough, it’s not on the A-plus exam. So you’re sitting there going, “Well, Mike, why did you just show me that?” Well, because you need to know it as a tech. What is on the exam is changing permissions within a Linux environment using the Chamod program. Now before I show you Chamod, let’s take a quick peek at Linux permissions. So, Poof, I’m going to convert this into a Linux machine. All right, so here I am on Linux. Now what I’m going to do is type LS, but I’m going to use the minus L switch on there. And you’ll notice that I have here two files and one directory. Actually, you can see them right here as well. On the far left, you can see the letter “D,” which stands for directory. So we’re going to ignore that for now. Gather is a folder. So it has that little D on the far left. It’s the other two that I’m interested in. So ignoring that first dash, it is read, write, and execute for the user, for the group, and then for others, or everyone. So every file and folder has this Rwx, Rwx, Rwx thing going. If you see a dash instead of one of those letters, it just means that permission has been disabled. So let’s go ahead and do a little bit of math to see how we can manipulate these different permissions.
I’ve got a file called Fred, and if we type LSminus L on the left side, we’ll see RW X, which means read, write, and execute for the user. Read, write, and execute for the group, and read, write, and execute for others. So what I’m going to do is have a little fun. So underneath this R, I want you to put the number four. Underneath this W, I want you to put the number two. And underneath the X, I want you to put the number one. And go ahead and do this for the other two groups of three. Okay, so what’s four plus two plus one? It’s seven. What’s four plus two plus one? It’s seven, and it’s seven. So if I want to change the permissions on the file to be read, write, and execute for the user, read, write, and execute for the group, and forever for everyone else, I’ll type a command like this. Chamad. Isn’t that a great name? And then seven, seven, seven, and then the name of the file, which will be Fred. By doing this, I have now granted the actual user read, write, and execute permission. The group that he’s a member of can read, write, and execute permission. And in fact, anybody who accesses this file will have read, write, and execute permission. That’s fun. Let’s do it again. So now I’ve got a situation where it’s just like a document, so it’s not executable. So let’s get rid of these ones. And what we have is that I want the user to be able to read and write on it. I want my group to be able to read and write, but everybody else only gets to read it. So let’s just do the math. Six, four.
So in order to set this up, I run the Chimad command. Six, four, and then the name of my file. I hit enter, and I’ve changed the permissions. So what I want to do right now is adjust my Fred file on my desktop so that anybody in my group can read and write to it. Right now, it’s just set to write. So let’s check this out. So let’s take a look here. We can see the Fred file right now. First and foremost, I am the proprietor. I can read and write to it, but everybody else can only read it. Do you see that? So let’s change that right now. Easy enough. We’re going to type in Chamad, six, six, four, and then Fred. And we hit enter, and nothing happens, which is good. But if I type LS minus L, you’re going to have to look very carefully. But you’ll notice that now my group has the right permissions. Chimod is a great tool. However, if you want to take advantage of it, you need to actually have ownership of that particular file or folder. So what I want to do next is show you how you can take control of any individual file or folder within the Linux environment using something called Chion.
So let’s do a quick change. So going to my previous example, we’ll see that I have a file called Fred in here. Now, if you look right now, the owner-user is Mike, and the group is Mike. So I’m going to own that. So I’m going to type “Chowne” and I’m going to change it from Mike to Timmy. And remember, it’s Fred that I want to do this with too. I’ve got a problem. The problem is that I didn’t use pseudo. So I’m going to just type in pseudochion, and I’m giving Fred to Timmy. And now if I type in LS, we’ll see that the user owner went from Mike to Timmy account.One more bit of fun, and we’ll be done. And that is how you change a password in a Linux environment. Now, of course, we can do these things through graphical tools, but to do it from the command line, we just type in the password. So the important thing about this is to first be logged in as the account that you’re interested in changing the password for. I’m currently logged in as Mike, so I’m going to go ahead and change the password. So we’re going to do sudo, enter the new password, retype it, and I successfully updated the password. All right, so the big takeaway from here is that we’ve got three commands I really want you to be aware of. Number one is Chamod, and that’s changing file permissions in a Linux environment. Use Chion to change the ownership. And last, but certainly not least, use PA SSWD to change your password.
10. Introduction to Scripting
If you asked me if there was one way that I could separate the real supertext from the regular run-of-the-mill text, it would be their ability to handle scripting. Scripting is a critical component for anybody who’s working on computers today, and that’s what we’re going to be doing in this episode. So, first of all, what is scripting? What you need to do is get yourself to a command line and recognise that, while the command line is powerful, we often find ourselves doing the same tasks day in and day out. For example, I have a bunch of log files I need to delete. So if you look at this folder, you’ll see I’ve got all of these old log files from way back when. It’s just sitting here, and I need to get rid of it.
Now what I can do is just go into a command prompt, head over to that folder, and just delete them from here. But I have to do this all the time. So I want to come up with a clever way to automate these boring tasks. And the tool we’re going to use, at least for this first job, is what’s known as a batch file. A batch file is nothing more than a text file. It’s just a text file, and you write it out in a text editor. I like to use Notepad when I’m on a Windows system. And really, all you’re doing is typing each line in a series of commands, just as though you were at a command prompt. You type each one and press the enter key. Let’s go ahead and whip up our first batch file. So I’m going to open up Notepad, and let’s go ahead and start typing. Remember, our job here is to delete those log files. So first of all, I want to get into that folder, so I’m going to have to type it in. Here we go. CD-spacey users Backslash on MichaelM’s desktop, logs So this is going to get me into that folder. And then I want to delete all the log files. So I type “Del Star Log.” Now, once I’ve typed all this in, what I need to do is save it with the extension.bat.
This particular program, Notepad, wants me to save it as a TXT. We’re not going to let them get away with that. So just by changing this to “asterisk,” “asteriskit” will now save with the bat extension. Now take a look at this. You’ll actually notice that the icon is a little bit different. I’ve actually turned on my file extension so you can see these, but even if it wasn’t, you can still see it’s a different type of file. So I’m going to go ahead and run this. Nothing happened, right? Well, yeah, it did. It got rid of all of those log files. Well, this is great for me, but what if I wanted to give my buddy Shannon the same batch file? In that case, it’s not going to do any good because it’s putting CDs into my home directories. So what can we do to get around that? Part of the answer is through what we call an environment variable. So I’m going to open up a command prompt and just type “set.” What you’re looking at here are environment variables. Environment variables are certain phrases that point to certain places or things that work for anything throughout the operating system. For example, here’s something called HomePath. HomePath.
Because I’m currently logged in as Michael M, MichaelM. However, if my buddy Shannon logs in, that will change, and the environment variable for HomePath will be changed to whatever Shannon’s folder is. So what we’re going to do is rewrite that batch file now, except I’m going to change the path a little bit so that we can get to anybody’s folder. doesn’t matter who’s logged in. So you’ve got to be careful. You see that right now; if we double-click on it, it’s just going to run. So I’m going to right-click on it and hit edit. So what we’re going to take out is this part right here. and watch how I replace this. HomePath percent is what I’m going to use. That will make whoever’s HomePathis active when they log in, replace it with their path, and it will work for whoever is logging in at the time. Batch files are fantastic, and people have been using them for 40 years now. Goodness, I’m old. Anyway, the downside to batch files is that, while they’re not very powerful, for example, I want to be able to delete log files, but I only want to delete log files that are, say, 15 days old or more old.In that case, batch files are going to have a little trouble. I’m sure there’s somebody out there right now going, “Oh, Mike, you could do it this way.” No, no, no. There are more elegant ways to do things. And Microsoft knew that, and many years ago it came out with an alternative shell called PowerShell.
So let me give you a quick tour. PowerShell. So in my version of Windows, I just right-click and select Windows PowerShell. And as you can see, I have a nice, pretty screen. Now, don’t let the colour fool you. Everything still works. Look, I can type dir, CD backslash, and get to the root directory. I can clear the screen. So the commands you’ve learned in other episodes still work perfectly well here. However, PowerShell has some pretty amazing features. One of the things I want to show you is that I’ve got a PowerShell pretty much already made. and you’ll see it’s right here. It’s called PowerShell PS One.And what I’m going to do is just right-click on this and open it so that it just opens in a notepad. So, wow, what have we got here? This is called a “git child item.” What you’re looking at is PowerShell really knows Windows. With PowerShell, you can query Active Directory, you can update your registry, and you can do all kinds of very powerful stuff through these little things called commandlets. If you really want to see commandlets, I get to show you something very cool called the PowerShell integrated scripting environment. So keep an eye on what we do this time around. I’m just going to right-click on it again, except this time I’m going to click on Edit. What you’re looking at is an environment that’s designed to help people write them. Keep in mind that a PowerShell script is just a text file. And what you’re looking at is an incredibly powerful text editor that helps you build these things. PowerShell comes with tens of thousands of discrete little commandlets. Nobody’s got this stuff memorized, but this helps you along.
So you can look here on the right, and it just shows you gazillions of all kinds of different commandlets for all kinds of different things. And no, I don’t know them, but there are tonnes of them in there. What’s also nice is that if you take a look across the screen here, you’ll see how the different colours show up. That’s basically the integrated scripting environment letting you know that everything looks good. If it had a problem, it would be highlighted right now. This is called the “integrated scripting environment.” PowerShell is incredibly powerful. If there’s something you need to do to Windows, there’s probably a PowerShell commandlet to help you do it. If you want to add users or change network settings, I literally can’t tell you all the powerful things that PowerShell can do. However, this isn’t just a Windows world. If you really want to talk about powerful shells, we have to talk about Linux and, in particular, the bash shell. Now, I’m going to pull up an example bash shell to show you right now, which I’ll do in Windows. Sorry.
I’m a Windows guy. So if you take a look, these bash scripts end with the extension sh. So I’m just going to double-click on this, and I want you to take a close look. First of all, do you see these little bangs? The number signs? Those are just remarks or comments that are put in there for people who are looking at this. To get an idea of why all this stuff is here, “Echo” just means to put something up on the screen. For example, “echo blank line” is a syntax. echo “repositories are being installed,” echo “blank line” Now here are the actual commands. This is very similar to what we’d see in a batch file. Now in other episodes we talk about pseudocommands and using app get and such. So these should look familiar to you. So you have all of this stuff, and it’s really just this one line that we have to deal with, and it just keeps going on and on like this, scrolling through with a bunch of commands, obviously installing something really, really big. Scripting files are crucial to being a good tech. Today it’s going to be on the A+, sure, but you should know these things. Make sure you’re comfortable with what a batch file is, what a PowerShell script is, and what a bash file is.
11. Interpreted Languages
In other episodes, we talk about stuff like processes, services, and applications, which are really just programs. What we’re talking about is stuff that is running on your computer and doing whatever we want it to do with our programs, our computers, or nothing. We have to have programmes that are doing stuff. But I often wonder: do people really know what a programme is? So I’ve got a bunch of programmes sitting on my screen right here. Let’s take a look. What you’re looking at is a bunch of files that have the extension “exe.” These are executable files. They are preset lists of commands that are designed to talk to Windows and your CPU. So where do these exe files come from? They come from programmers. There are people who know how to write these types of code so that they can get work done. The problem we have here is that these.exe files are what we call “compiled code.”
Now the idea behind these is that we still write these programmes out in some kind of programming language. But something very different happens with these. Built into every different operating system is what we call an interpreter. So these interpreters work in Windows and will work on a Mac. They work on Linux. They may not work for all of these programmes in all of these different operating systems, but they do the majority of the time. And the cool part is that, in order to run this program, it is never turned into an exe. We simply take the code, run it through the interpreter, and it comes out and does whatever it needs to do. Interpreted code has some real benefits. We could write one piece of code, and as long as we’re not asking that piece of code to do something very Mac- or Windows-specific, we can take one piece of code and it’ll pretty much run on any operating system we want. The trick is that the operating systems have to have the right interpreters in them. So really, what I want to talk about is the different types of interpretive languages that we’re going to see both on the A-plus and in the real world. And also keep in mind that we often use the term “scripting language” interchangeably with the concept of something that’s just interpreted. So, if that’s okay, I’ll use scripting language. One of my favourites to go to first is good old Visual Basic. It’s been around a long time, and, well, Mike knows it pretty well. So I’ve got this little file right here, and his name is Test DBS. That’s a Visual Basic script, and it’s really just a text file. So let’s go ahead and edit it so you can see it’s just a text file. I’ve got it. Open up a notepad. First of all, you can see some commentary marks there in this language. It’s just a little apostrophe. Now what I want you to look at is right here.
Do you see where it says Dim? What we’re talking about here are variables. Variables are values that can change based on how we manipulate them. So you can have different types of variables. In this particular one, you’ll see that it just says dimension number one, number two, and number three. Now, because it says “numb,” you’ll go, “Oh, Mike, that means it’s a number.” Well, it may be or it may not be. What we’re looking at in most of these interpreted languages is that they’re pretty flexible. In certain languages, you have to be very specific when you make a variable. For example, you have to say that this variable will be an integer or that this variable will be a string value. A string value basically means anything you want to put in there. By setting up the different types of variables, we can use less memory and have better control over them. For example, if we dimension a particular variable as a string, we’re going to try not to add them together. That makes sense. Whereas if I put them up as integers, then we may want to go ahead and add them together. Different languages have different ways to handle this, but be aware that we declare variables and we declare them as a type.However, in a lot of languages, you just declare them like we see here in Visual Basic, and they’re pretty much all going to be strings, even though it says “number.” In fact, that’s going to be a problem as we write this code. Let’s take a look. So it declares these variables, and then it’s going to give numbers one, two, and three a value.
And it says, “Please enter the first number, second number, and third number.” We’ll see how this works in just a minute. And then it’s going to do a little check. For example, if these values are numeric, then, and this is a conditional if, then right here. And here’s some more commentary. Let us know what’s happening. “Put an output statement telling you to improve these three numbers,” it’ll say. Now the problem here is that these have been declared as being basically strings because it doesn’t say anything up there. So it has to say in Visual Basic that this value CDBL means I don’t care what this has turned into as a number. So, if the CDBL of NUMBER 2 is greater than the CDBL of the current largest number, NUMBER 2 is now the largest number. Get the idea? And then, when the third number comes along, do it again. So basically, this piece of code is going to ask us to enter three numbers, and then it’s going to tell us which one is the largest one. So it’s fun to look at the code, but let’s actually run it. That’s even more fun. So this is an input box. So I’m going to put the number two, and then I’m going to put the number 55. I’m going to put 16. And it says, “You have entered these three numbers, and the largest number is 55.” It’s pretty cool how Visual Basic gives us the opportunity to work with graphical boxes and such. In fact, pretty much all scripting languages do. You could also run them just fine from the command line. It’s just a matter of personal choice more than anything else. Alright, now what I want to do is move on to something a little bit more. What’s the word I’m looking for? Widely used. Visual Basic is fantastic. There is nothing wrong with it. However, it’s pretty specific to Windows. You’re not going to find an interpreter for Visual Basic on a Mac. I’m sure there is one, but they’re not common.