5.1 Windows Advanced Piping and Ampersands

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *

Already have an account? Sign In »

5 hours 21 minutes
Video Transcription
Hello and welcome to command line basics. This video we're gonna go over piping an ampersand commands at the command line and how we can use them to our advantage. I'm Crystal Hyler and this begin.
So we're letting objectives for this video. We're gonna learn what piping and used for what the single and the double pipes do and understand what the single am percent and the double ampersand operations are used for and how we can use them at the command line.
Our pre assessment, which offering runs command to if command one fails. Is it a command? One single pipe command to be command one double pipe command to see command one single ampersand command too,
or D command one double ampersand command, too.
Answer is B command one double pipe command to and as well learn in this video, the double pipe will run a second command if the first command fails. This is very useful for trying to keep track of Ah, if a certain command is working properly or not,
and similarly with the double am percent, it will run command to if command one is executed properly. Not if it fails. So we'll learn more about this in this video.
All right, so the single pipe, this is something that we've done a lot already. In this course, it'll take these standard output from the first command, and it will pass it as standard input to this second command. Very useful way to link to commands together. And it gives us a lot of really strong functionality and opportunity at the command line. And
as we were using it, it's used a lot with less or more,
and we can also use it with grip so that we can look through and grab for files and, you know, execute these different commands together by piping all of the output to Thea later commands so very useful. You should be very comfortable with the single by because you're going to use it a lot at the command line.
And it is a very, very effective way
to utilize the output from commands in order to be able to, uh, run additional commands and manipulate that data.
So the double pipe this is used to execute a second command on Lee. If the 1st 1 fails. So this is really useful of re looking for functionality or if we're using it in scripting where you know, if we're running a script and we're going through a huge list of computer names and let's say that it cannot connect to a specific computer name,
Well, if we use the dumbbell pipe, we can say,
Hey, if this command does not work for this computer because that computer's off line or it's not connected shutdowns, you know, whatever reason it is, then I want you to echo. Hey, I can't connect. And as you can see in this first example, if we do Ping, this host does not exist. It will echo Hey, I can't ping it.
So, uh, let's give a quick demonstration of that.
when I do think this does not not that exist and this is not a real address, so there's no way he's going to ping it.
We'll do a double pipe echo.
I can't ping.
And now, since we know that this host does not exist, we can already know that this ping command is going to fail. Since we're using the double pipe, we know that it's going to execute this echo command,
so check it out. So the Ping request could not find the host. This does not that exist.
And since that command failed, it ran the echo. Come in. I can't think.
And now we can validate this where we can ping are looped back address. This is 1 27 0.1 If you're not familiar with Luke back, it is a non redoubtable, only local system address. So we know that every single time is going be able to ping this and since it can think it is going to ignore
this dump the pipes
so don't run through really quick
and never go. It finished the thing and we did not get the echo I camping because that first command executed properly
are some of the 1% a single ampersand on windows. It is used to execute a additional command after the first command. This is not check for any error or any success for the first Command, and it is really useful. Be able to submit a bunch of different commands all on the same line.
So this is a useful way to string a bunch of different commands all together, all at once.
And if you're not familiar, with Lennox. It's similar to the semi colon on the Lennox show,
so we'll do a quick demonstration of that where I will do Echo one
ampersand echo, too. So it's going to do echo for one and then immediately execute Echo, too.
And as you can see, we have one enter, too, so executed those commands directly,
and it does not check for an air of her success.
For Lennox, the single air percent is used to execute and run a process in the background. Now, when I'm using the Onyx Terminal, I like to use the single ampersand to start a googly application from the command line and allows me to keep control of the terminal as well.
So, uh, that's a really useful application of being able to use it.
You can do a quick demonstration of that, so I have my lyrics meant machine up. Now let's say I want Thio Open up Fire Fox. So I'm going to type in Firefox and a single ampersand
and, as we can see, is starting on page 36 62. I still have control over my terminal, and Firefox has taken its time starting up and here we go. So we got fire Fox up
where? If we just type fire Fox without the Let me spell that properly.
Firefox without the and percent
then the terminal is going to hang, and it will only give us access back to the terminal once Firefox is closed.
So as you can see, we're gonna type in and everything, but nothing is not any working. So let's close it out.
And now it'll finally give us access back to the terminal,
all right? With a double and percent. So what this does is it will execute a second command on Lee if the first command was successful,
so it will only execute if there were no errors on this first command. So this is another useful way to be able to use, uh, these kind of operations in order to get what we need.
So this is the opposite of the double pipe where if we ping, you know our loot back address and say echo good, we know every single time that is going to be a valid excuse.
And then if we think something that we know is not going to work, then we know that where are not going to get that echo because it only works on two on a successful command.
So let's say
Ping 47 year 01
double ampersand
And since we know we can always paying our loop back address, it's always going to echo works that second command now. Likewise. If we do a host, let me know does not exist. This does not exist.
And then we run the double ampersand and echo works.
We know it will not work. See, we had the error for pain because it could not work properly. And it did not execute that second command.
My post assessment which operation will execute command to if command one is successful.
Is it a command? One single line. Percent command too.
Be command one double ampersand command too.
Sea command, one single ampersand, single paper command to or D command one. Double pipe command too.
Answer is B command one double ampersand command to this operation on Lee Execute Command to if command one is successful and similar to the double pipe. This is a very useful way to be able to control the flow of data and help identify commands that should be running probably and should not.
The single ampersand is used for its own specific ways. And Windows and Lennox, not Thio
help with the command flow.
That single ampersand single pipe is not a valid combination of these characters on the double. People only execute command to you if it is unsuccessful for command one
are so in this video, Willard, what piping is used for learned but single and double pipes do and understood the single and percent in the double and percent operations And how we can use them at the command line to our advantage. And I hope to see you in the next video.
Up Next