5 hours 21 minutes
Hello and welcome to command line basics. In this video, we're gonna go over command redirection. I'm Crystal Hyler and let's begin.
So are learning objectives for this video. We're gonna understand the purpose of redirection and why we should do it and how we can do it properly.
Learned what this greater than symbol does. Learn what the double greater than symbol does and what the less than symbol does.
So which operate in a pens to an existing files. Is it a single less than be a double less than see a double greater Than or D a single greater than
the answer is seat The double greater than with this stuns is it will upend to an existing file, whereas the single greater than will overwrite existing file if it exists already,
the single less than is used for input into a different command and the double less than is not a valid operate.
So the redirection, the whole purpose of redirection from the command line, is that we can use the output and either save it or we can direct input using the less than symbol so we can specify, you know, different standard out or standard area levels of redirection as well instead of just the normal ah,
So it's just a useful way to be able to. You either gather information from the output of command that we can search through later or save it and keep it in a different place.
So the single greater than what this does is it just simply takes the output from a command. It will stuff it into a file on the system.
If the file does not exist, it will create it automatically. Now the big thing to keep in mind single Raider then, is that it will override a file if that file does exist. So that can be a problem if we want to keep you know, the rest of the information in that file ready?
So let's go ahead and give a quick demonstration.
So I'm going to you, dear. So we can see what's inside of this.
Now let's say echo
And we're gonna use the single
and percent and put it into
and load, uh, 60
or excuse me, not 9% but single. Greater than And now if we do another dir Sylvia. Hello, Don t x t
and let's do type.
Hello. You could see Hello there.
And now if we do this again But instead of hello,
Now with the single greater than it's going to overwrite the helo
And now we can do type again. We can see the helo is gone and all we have left is a high.
Now, In order to overcome this, we can use the double greater that found what this does it pens to the end of the file if it does exist. So we don't want to override everything in the file ready. We use the double greater than I am, and it will automatically put it at the bottom of the file. So we don't keep overriding something that we want to keep in there already.
And just like the single greater than it will create a file if it doesn't exist already.
So let's give a quick demonstration of the double greater than and how we can use it to not overwrite what we're working on.
All right, so let's say go.
This didn't overwrite
and the double greater than
and load out t x t.
Now if we do type
for hello we can see we have This didn't overwrite on the end of the file that was already there, and it did not overwrite the high that we previously just did.
So this is very useful to keep in mind as we are redirecting output into files that we don't want to override things that we want to keep in there
when we had the single greater than what this does. It is used to provide input from a file into a command, and this file must exist because you are providing it as input and it will not change the input of the file
so it will leave the fallout. The same will simply provide that file as input into the command
so we can use the sort command and the less than to say, Hey, I'm pushing this filed off t X t into the sort command.
So let's give a demonstration of that. I'm gonna pull up by the Lenox machine
and just like always, I'm gonna type l s to see what is inside of this directory.
And now let's say I want a sort Latin words that t x t do sort
and letting words that t x t with my less sensible
and look that goes head takes it as input sorts more A lot for me, pretty useful.
And now we can also redirect standard error from commands as well. And this is something you may have seen already. Where If there is a lot of veritext, especially if you're doing search and you know the command doesn't have full access to the system, it will give you errors saying, Hey, I can't reach this. And that could take up a lot of screen information.
So we can do is we can redirect that standard error into a place that doesn't exist on limits. That is, a dead no, a slash, stab slash null. And anything sent to this directory on Lennox is immediately dropped and just ignored. And now, in order to specify standard error,
we're gonna use the two and then the single greater than And this says, Hey, uh, for any ever is that you get one. This command is running. I want you to take it and spit the standard error into this specific location and using the Dev. No, it says, just get rid of it.
this is a useful way to be able. Thio. Ignore all of the air information. So let's say I'm gonna use my legs machine and I'm gonna search for my program on the route of the drive.
Now, as you'll see, let's take that grip part I my program
forward slash for the room.
Now you'll see I will have a lot of
This is my bash history
and now I should have a lot of permission denied. There we go.
So there's way too much going on right here.
It's taken over my entire terminal. I I'm gonna use control. See, Stop this before it takes up more space
and then d'oh! Clear Nazi Less so that I can get back to that kind of default position on the terminal. Now if I do
This saying I want you to take these standard error and pushing into Dev. No.
So, as we'll see, we won't get all those errors because it's all the error messages that it gets. It automatically sends. Do that slap have slashed no directory where it is dropped by the Lenox system. So that way we can focus on directly just what you know the output we have.
So here we go. So I can already see, you know, some different, uh,
information coming back. We don't have all these error messages coming all over screen and taking over our, uh, her
our command window. Excuse me?
Aren't supposed to. Says which operate overrides an existing file. Is it a single west than the double? Less than
see single greater Than or D A double greater than
answer is C a single greater than this will overwrite existing file. And it will not depend to the end of the double greater than well up in to the end of a file if you want to keep it. But if you don't care too much about it or you just need to create a new file the single greater than work exactly what you needed to
and the single less than is used to provide input to a command, not Thio. Get at the output for
All right. So in this video, we learned the purpose of redirection and how we can use at the command line learned what the single greater than does learn with the double greater van does and how it depends for the file and keeps the file and understood with single West, then does and how we can use it to our advantage, and I hope to see you in the next video.
SOC Analyst Assessment Level 1
Cydefe's SOC Analyst Assessment, Level 1, Capture-the-Flag (CTF) Assessment
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered