Time
5 hours 21 minutes
Difficulty
Beginner
CEU/CPE
6

Video Transcription

00:00
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.
00:11
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.
00:25
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,
00:41
or D command one double ampersand command, too.
00:46
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,
01:03
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.
01:17
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
01:37
as we were using it, it's used a lot with less or more,
01:40
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.
01:59
And it is a very, very effective way
02:00
to utilize the output from commands in order to be able to, uh, run additional commands and manipulate that data.
02:09
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,
02:30
Well, if we use the dumbbell pipe, we can say,
02:32
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.
02:52
So, uh, let's give a quick demonstration of that.
02:55
So
02:58
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.
03:07
We'll do a double pipe echo.
03:09
I can't ping.
03:14
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,
03:25
so check it out. So the Ping request could not find the host. This does not that exist.
03:30
And since that command failed, it ran the echo. Come in. I can't think.
03:35
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
03:54
this dump the pipes
03:58
so don't run through really quick
04:00
and never go. It finished the thing and we did not get the echo I camping because that first command executed properly
04:09
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.
04:27
So this is a useful way to string a bunch of different commands all together, all at once.
04:32
And if you're not familiar, with Lennox. It's similar to the semi colon on the Lennox show,
04:39
so we'll do a quick demonstration of that where I will do Echo one
04:44
ampersand echo, too. So it's going to do echo for one and then immediately execute Echo, too.
04:50
And as you can see, we have one enter, too, so executed those commands directly,
04:57
and it does not check for an air of her success.
05:00
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.
05:17
So, uh, that's a really useful application of being able to use it.
05:21
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
05:34
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
05:47
where? If we just type fire Fox without the Let me spell that properly.
05:54
Firefox without the and percent
05:56
then the terminal is going to hang, and it will only give us access back to the terminal once Firefox is closed.
06:05
So as you can see, we're gonna type in and everything, but nothing is not any working. So let's close it out.
06:13
And now it'll finally give us access back to the terminal,
06:17
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,
06:25
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.
06:35
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.
06:46
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.
07:00
So let's say
07:01
Ping 47 year 01
07:04
double ampersand
07:06
echo
07:09
works.
07:11
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.
07:27
And then we run the double ampersand and echo works.
07:30
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.
07:39
My post assessment which operation will execute command to if command one is successful.
07:45
Is it a command? One single line. Percent command too.
07:48
Be command one double ampersand command too.
07:51
Sea command, one single ampersand, single paper command to or D command one. Double pipe command too.
08:01
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.
08:20
The single ampersand is used for its own specific ways. And Windows and Lennox, not Thio
08:26
help with the command flow.
08:28
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
08:39
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

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