Hello and welcome to your module 103 dot for where we're learning about streams, pipes and redirection.
Now we've already covered these topics a little bit, but we've got some additional things to consider. Mainly the use of the T Command and the ex Argus Command.
These air very flexible
components within limits allow us to do
a little bit more with
the input and output of one command to another.
We've already talked about standard in standard out and standard error
and their file descriptor numbers.
So everyone should be pretty familiar with what these things are.
And we'll see a little bit later how these file descriptors work. But
just keep in mind that zero is for standard and one is for standard. Out into is for standard error,
and we'll we'll see why that matters a little bit later.
Already covered several examples of using the pipe command takes a standard output of one command and send it to the standard input of another.
Did example very similar. This
cutting some fields out of the shadow file.
Maybe I'm running nuts, Dad and I want to identify those ports. They're listening, and then sort them
now there's really no practical Limited's fires. How many commands I can pipe into another command?
The main limitation would be is it actually something useful and functional?
as I see as we see here to pipes, or I can have a situation where there's 45 It really doesn't matter.
It's up to me to decide what's needed by mine. By my command,
we can think of pipe as always, input being I'm sorry. Always as output from standard output being sent to standard input of another command,
whereas redirection could go either direction.
So there's an important distinction to make.
Then we have the X Argus Command. This utility elect will let me read
arguments from the output of another command.
So if I run l s and pipe that X, our eggs,
I can list my files and it treats this echo my files colon
as, ah command. But it uses the output of L s as the arguments to that command.
So let's try a few of these things out, um, Aiken
and tell ex arcs to remove whatever gets returned by the fine statement.
So again, we can tell that there's
more than one way to accomplish various goals.
So a simple example I'll do in L s
pipe that X are eggs and say, Oops, I go my files.
And there they are. No, that
isn't very useful because it's not formatted very well, but
you can still see my files is here, and then it lists Does a long list in each of those.
I can also take it a commandment l s and run that. Two ex artisans say we actually want to do it a long listing when I run l s.
And we can see that that actually worked
And then the remove command any any command that I wish
I can send the upward of one command and use those put items as an input to X are eggs and tell it to run some other command based on what those arguments are.
And obviously you could These are very powerful tools, and we have to be careful how we use them so that we don't actually accidentally do something
you know, it might not be a difficult, uh, might be difficult rather to under
so play around with X R exits. Ah, well worth
learning more about because it's got so many powerful features.
Look at our help screen.
Few options here for things like replacing files
D ha deal properly with Spaces and tabs
and whether there's blank lines.
Now, when we send output using the pipe character
to another program, that's pretty useful. It's not quite the same thing as redirection redirection.
I can run a program and redirect toe a file name.
It'll create this file but doesn't already exist
if I use a double greater than sign that will upend to that file name,
and then I can also use those file descriptor numbers, as I mentioned earlier.
For instance, if I run the L s command, I can redirect that output to Espen, not text,
and I can redirect standard error, which has followed the script or two
to Espin dot error. If there was any errors for the L S command, they will show up in this separate file, which has redirected Onley four errors.
Sometimes when you're running a script, especially if it's a part of a crown job or something like that,
you may want to get rid of errors because they may cause problems with the execution of the script. So a typical way to do that
is to redirect, redirect file descriptor to standard air
to something like Devon. All
and it's basically will
allow the system take all the errors and send it to the bit bucket. As it's called, they don't get saved anywhere they just get
deleted more or less.
That's pretty useful
when you're running script, especially because I want to be able to capture errors in a separate file. Or maybe I don't care about them because they might be interfering with the operation that I can just discard them.
If I don't use these re directions specifically for error, it will get redirected to standard Out,
which would have been captured in this has been dot text file.
In some cases, that might be what you want. It just depends on your needs at the time,
and we have the T command.
So this is nice because I can take the output of ah command and pipe into T
and then save that I'll put in another file
So let's do an example or to with this.
So first, I'll, uh, do a redirection.
I'll do it. L s Dash l of Espen
It has been Don't text.
all I got actually should have done l s
You should know that differently.
Here we go. So I didn't use the wild card for everything underneath directory. Now I've got my directory listing saved as a file.
Now, at the end of this file,
I could do a tail on it. I can see the last item is has been
What if I want to put some
information there can say echo
Just an example of how you might do this. I can use a double redirect which will upend this message
to as being that text.
Now, if I do a tail,
I can see the last 10 lines, which includes that little bit that I just depended.
Be careful with the pending versus creating. If I use a single redirect, it will create a new file or overwrite existing file, whereas double redirect.
append to the current file
now with the T Command.
Let's go back to this.
So there's the output of that command. I can pipe this to t
and I could say I want to create I'll call. This one has been to dot text.
but has been to dot text also got created.
look at the file, it has the same content as that
as what went to standard output.
So it was very handy because now
I can run commands. I could be doing things. And I can also be saving all the output from those Koreans in a file
and during troubleshooting
practices or other things that you're doing, you might find this very useful.
Now what if I want to get a little bit more fancy? I could
also take the output that I created and count it.
So I'm gonna do a long list of Espen which will go to the screen.
The T command will send the output to a file called Has been to dot text
standard out will, because I've used a second pipe standard out is only going to get the last command, which tells me how many files
but s been to still was created the same way as it was before.
uh my my use that he can t command basically overrode the previous version of that file.
So practice with these and, uh, get familiar with how you passed
or past the output of one command as arguments to a new command with X, our eggs.
the copy of standard output into another file with the T command.
Next, we're gonna talk about creating processes, monitoring them and learning how to kill them.
All right, See you there. Thank you.