Time
8 hours 30 minutes
Difficulty
Beginner
CEU/CPE
10

Video Transcription

00:04
Hello and welcome to your module 103 dot for where we're learning about streams, pipes and redirection.
00:11
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.
00:21
These air very flexible
00:23
components within limits allow us to do
00:26
a little bit more with
00:28
the input and output of one command to another.
00:33
We've already talked about standard in standard out and standard error
00:38
and their file descriptor numbers.
00:40
So everyone should be pretty familiar with what these things are.
00:44
And we'll see a little bit later how these file descriptors work. But
00:49
just keep in mind that zero is for standard and one is for standard. Out into is for standard error,
00:55
and we'll we'll see why that matters a little bit later.
00:59
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.
01:07
Did example very similar. This
01:08
cutting some fields out of the shadow file.
01:11
Maybe I'm running nuts, Dad and I want to identify those ports. They're listening, and then sort them
01:19
now there's really no practical Limited's fires. How many commands I can pipe into another command?
01:25
The main limitation would be is it actually something useful and functional?
01:30
But I can have,
01:30
as I see as we see here to pipes, or I can have a situation where there's 45 It really doesn't matter.
01:37
It's up to me to decide what's needed by mine. By my command,
01:42
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,
01:51
whereas redirection could go either direction.
01:53
So there's an important distinction to make.
01:57
Then we have the X Argus Command. This utility elect will let me read
02:01
arguments from the output of another command.
02:06
So if I run l s and pipe that X, our eggs,
02:09
I can list my files and it treats this echo my files colon
02:15
as, ah command. But it uses the output of L s as the arguments to that command.
02:22
So let's try a few of these things out, um, Aiken
02:25
to a fine statement
02:28
and tell ex arcs to remove whatever gets returned by the fine statement.
02:32
So again, we can tell that there's
02:34
more than one way to accomplish various goals.
02:38
So a simple example I'll do in L s
02:42
and
02:43
pipe that X are eggs and say, Oops, I go my files.
02:52
And there they are. No, that
02:54
isn't very useful because it's not formatted very well, but
03:01
you can still see my files is here, and then it lists Does a long list in each of those.
03:12
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.
03:24
And we can see that that actually worked
03:28
pretty handy.
03:29
And then the remove command any any command that I wish
03:34
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.
03:44
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
03:51
that that we
03:53
you know, it might not be a difficult, uh, might be difficult rather to under
04:00
so play around with X R exits. Ah, well worth
04:02
learning more about because it's got so many powerful features.
04:06
Look at our help screen.
04:10
Few options here for things like replacing files
04:15
D ha deal properly with Spaces and tabs
04:17
and whether there's blank lines.
04:26
Now, when we send output using the pipe character
04:29
to another program, that's pretty useful. It's not quite the same thing as redirection redirection.
04:35
I can run a program and redirect toe a file name.
04:40
It'll create this file but doesn't already exist
04:43
if I use a double greater than sign that will upend to that file name,
04:50
and then I can also use those file descriptor numbers, as I mentioned earlier.
04:55
For instance, if I run the L s command, I can redirect that output to Espen, not text,
05:01
and I can redirect standard error, which has followed the script or two
05:05
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.
05:15
Sometimes when you're running a script, especially if it's a part of a crown job or something like that,
05:19
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
05:28
is to redirect, redirect file descriptor to standard air
05:31
to something like Devon. All
05:33
and it's basically will
05:36
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
05:44
done,
05:45
deleted more or less.
05:47
That's pretty useful
05:49
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.
06:01
If I don't use these re directions specifically for error, it will get redirected to standard Out,
06:09
which would have been captured in this has been dot text file.
06:13
In some cases, that might be what you want. It just depends on your needs at the time,
06:18
and we have the T command.
06:20
So this is nice because I can take the output of ah command and pipe into T
06:26
and then save that I'll put in another file
06:29
very, very handy.
06:30
So let's do an example or to with this.
06:42
So first, I'll, uh, do a redirection.
06:45
I'll do it. L s Dash l of Espen
06:47
and I'll save this.
06:49
It has been Don't text.
06:53
Now if I
06:56
do amore on that,
06:58
uh,
07:00
all I got actually should have done l s
07:03
on the
07:08
You should know that differently.
07:14
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.
07:25
Now, at the end of this file,
07:27
I could do a tail on it. I can see the last item is has been
07:30
Z Bram Control.
07:33
What if I want to put some
07:35
information there can say echo
07:41
and, uh, listing
07:43
Just an example of how you might do this. I can use a double redirect which will upend this message
07:49
to as being that text.
07:54
Now, if I do a tail,
07:57
I can see the last 10 lines, which includes that little bit that I just depended.
08:01
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.
08:09
Well,
08:11
um,
08:13
append to the current file
08:16
now with the T Command.
08:20
Let's go back to this.
08:24
So there's the output of that command. I can pipe this to t
08:30
and I could say I want to create I'll call. This one has been to dot text.
08:35
So I saw the output
08:37
that's there
08:43
but has been to dot text also got created.
08:45
And if I were
08:50
look at the file, it has the same content as that
08:52
as what went to standard output.
08:56
So it was very handy because now
08:58
I can run commands. I could be doing things. And I can also be saving all the output from those Koreans in a file
09:05
and during troubleshooting
09:09
practices or other things that you're doing, you might find this very useful.
09:15
Now what if I want to get a little bit more fancy? I could
09:22
also take the output that I created and count it.
09:26
So I'm gonna do a long list of Espen which will go to the screen.
09:30
The T command will send the output to a file called Has been to dot text
09:35
and
09:35
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
09:41
were created,
09:46
but s been to still was created the same way as it was before.
09:50
And because I,
09:52
uh my my use that he can t command basically overrode the previous version of that file.
10:00
So practice with these and, uh, get familiar with how you passed
10:05
commands from
10:07
or past the output of one command as arguments to a new command with X, our eggs.
10:11
And then I can save
10:13
the copy of standard output into another file with the T command.
10:18
Next, we're gonna talk about creating processes, monitoring them and learning how to kill them.
10:24
All right, See you there. Thank you.

Up Next

CompTIA Linux+

Our self-paced online CompTIA Linux+ course prepares students with the knowledge to become a certified Linux+ expert, spanning a curriculum that covers Linux maintenance tasks, user assistance and installation and configuration.

Instructed By

Instructor Profile Image
Dean Pompilio
CEO of SteppingStone Solutions
Instructor