Time
5 hours 21 minutes
Difficulty
Beginner
CEU/CPE
6

Video Transcription

00:01
Hello and welcome to command line basics. In this video, we're gonna go over command loops and how we can use them on Christopher Handler and let's begin.
00:09
So we're learning objected to this video. We're gonna learn the purpose of the command. Lupin. Why? We're going to use it. We're gonna learn the difference between a Lennox Command Luke and Windows commands. Look,
00:20
it's a pre assessment wire loops. Useful. Is it a two complete repetitive tasks be they do not overload the system. See, they will stop automatically. If it's to resource intensive or D, they will automatically execute new commands.
00:36
The answer is a they complete repetitive test. Just like any other computer. They're used to complete repetitive tasks, so we don't have to do him ourselves. So that's why it looser, useful, automatically do things for us,
00:50
and they can overload the system because of the nature of loops where they keep doing things over and over. So if you explicitly told it to do something and you don't give it a limit to stop, it will completely overload the system, and they will not stop automatically if they are using to any resource is
01:07
because the computer is doing exactly what you told it to,
01:11
and they will not execute any command that is not a part of the loop already. So it is only doing what you tell it to, as we said already, so it will not automatically execute new commands in the loop.
01:23
So the whole purpose of four and while loops is that they are going to keep going through a specific set of requirements, salute through until they're met.
01:33
So we can either tell it to you run a specific amount of times or you can say, Hey, I just want you to keep running forever.
01:41
And we can take it either for, you know, file or a number, so we can use the file as input. If we say we have a different computer name on each line of file, we can tell it Hey, for each line in this file, I want you to ping
01:56
so it will go through an It'll ping for every single line for those computer names inside that file
02:01
and the while in the background, it will, you know, evaluate if the condition is true or not, and it will keep going until that condition is met,
02:13
and it's very important to keep in mind that loops will do exactly what you tell him to.
02:17
So if you say well, while something is true and that's always true, it is always going to run and it will never stop. So that is an easy way to overload your system s. So it's very important to keep in mind what you're doing and how you can prevent a four look for going out of control.
02:35
It's the limit sloops. We'll learn about these first, and they have three basic components, so we're going to define the parameter that we're going to use and the loop condition.
02:45
So as you can see in our example here, we were using the eye parameter, and you can choose what every letter you'd like over where a deal like that's not specific. What's important is that you use the same parameter later on in the command to execute.
02:59
So as we can see in the second part here, we have the eye with a dollar sign,
03:05
and this is the parameter we define already in the first part of the component for the loop
03:12
and noticed that they are separated by a semi colon. Each part of this. So we're saying four eye in this list of numbers from one through five.
03:22
I want you to echo I
03:24
and then done
03:27
so. This is a very useful way to be able to say Hey for this specific number of steps. Go ahead and execute this.
03:35
So let's get into my Lennox machine
03:38
and this is the command that we just had on the screen. And it does echo one through 51 of the time because there's a looping through this list of numbers and is doing this command for every single one.
03:51
Now, if we do a four loop, let's say, while this is true,
03:55
I want you to echo running,
03:58
and since true is always going to be true, this will keep running until we interrupted.
04:04
So while this may be funny and you know something exciting to know that yes, we can do this. It's very important the stop this from running so we don't eat up all of our resources or have it wasting, you know, processing power.
04:17
So let's go ahead back into my limits machine
04:20
and we have the same command while true Do echo running done.
04:27
And as we could see, it is running and it is still going. So I'm gonna hit control C because I don't want this to keep going crazy.
04:33
So that's useful to keep in mind. As you know, we're working through these four loops.
04:39
Now we can use a file lupas Well, where we can look through the file input for a lived command, and then we can execute commands from that file input. And like we were saying at the beginning of this video, if we have a specific, uh, file full of computer names, we can have it. Ping, all those computer names,
04:57
we're in this example. What we're gonna do is we're gonna take the eye and then have it execute
05:02
all of the words inside of this words that t x to you file and have it echoed them.
05:08
And this dollar sign cat
05:11
file. What this does is it is ah executed a command within the command already within this loop. So this is a very useful way to be able thio, get specific output and, you know, work these commands together.
05:26
So for windows loops, what we can do is we have, ah, few different subsets that we can use. We have these flash l for a list of numbers and we also have the slash f for some file input that we can use as well.
05:36
So we can use a slash l for ah, list of numbers. And this is ah,
05:44
this starting number for one. And then the one is the amount of steps to increase or every every time we go through one of these numbers and the 15 is the last number two head on. So this is saying hey, for this list of numbers with the parameter G,
06:01
this is the way that when does defines parameters for loops is using the percentage and then the
06:08
letter that we can use. This could be any later. Just like for Lennox.
06:12
Uh, in this list of numbers, I want you to echo the G parameter, so it'll go through one by one, and it will echo for us. Let's give a demonstration of that.
06:23
So at my command, prompt.
06:25
I have four forward slash l
06:28
percentage G in this list of numbers were in echo G
06:33
and check it out went through. Don't LaFours very useful.
06:38
Now we can do the same idea with this as well. Except if we don't define
06:44
a list of numbers for this slash l This is just a lower case. So, uh, it will run infinitely. It won't stop because there was no defined limits for this list to stop running.
06:56
So if we go back to my command, prompt
06:58
and I have our four forward slash l g in nothing. So just these empty parameters just echo. Oops.
07:06
And it is going to keep echoing that because there is no limit set on this force is for Luke.
07:14
No, If we do this slash f can take file input.
07:17
So let's say in this ward stopped t x t. I want you to echo everything inside of this words file.
07:24
So let's go back over.
07:27
And so we have our four ford slash f parameter g. Inside of this words file do echo g.
07:34
And here we go. So it will echo each line separately.
07:39
So very useful.
07:44
All right, So post assessment, what is the purpose of the parameter in a four loop? Is that a and marks the files for input be creates unlimited looping see assigns multiple variables or D. It's used to track completion of the loop.
07:59
Answer is D. The parameter is used to track completion off the loop. So this is a very useful way. Thio, take those specific parts of the loop and, uh, you know, use it in the loop to keep looping through these different commands that we want execute for us so we don't have to type it on our own,
08:18
right? So in this video, we understood the purpose of a command. Luke. We learned the Lenox Loops and we'll learn Windows loops and how we can use him for our advantage, and I hope to see you in the next video.

Up Next

Command Line Basics

In this course you will learn the fundamentals of Command Line basics, a fundamental tool for any user of Windows and Linux machines. Command line allows developers to manipulate files easily and quickly, Learning command line saves developers time and resources.

Instructed By

Instructor Profile Image
Christopher Haller
Senior Intelligence Operations Analyst at Centripetal
Instructor