[No audio]
Pipes. A pipe is used by the shell to connect the
output of one command directly to the input of
another command. The symbol for a pipe is the
vertical bar, the command syntax is command, or
the option or the argument, and then you pipe it,
to another command, whether it's option on
argument if there is any. Basically, if you want
to connect two commands together, or if you want
to take the output of the first command, and pipe
it to a different output, then you could use a
pipe. In a Mac keyboard, a pipe is somewhere the
key all the way to the right, that looks like
that. And in a regular keyboard, you will see the
pipe option is right below the backspace. And you
could do I think, with the shift and pipe. So the
way it works is you have a, you have a command, it
goes into a pipe, and it comes out the output. So
let's say if you have ls -l, that's a command
you run, you pipe that, the exact same pipe
character that you use, and you put another
command to it to refine the output of your last
command. So let's look at the example in our Linux machine.
[No audio]
If we are in slash etc directory, by the way,
where we are? We are in our home directory. So if
he if we go into cd /etc, now this
directory has a bunch of files and directories,
which you can now view all in one page, it will
display all at once. But everything will scroll up
so fast that you wouldn't even able to view one by
one. So when you do ls -ltr, you hit enter.
You see, it went up so fast. What you could do,
you could scroll up, of course, when you do,
scroll down slow by slow, you're gonna see all
those files, commands and directories that are
inside of etc. Now you want to view all of them
one page at a time. So how do you do that? The way
you do it, you put it in a pipe. So first you
do ls -ltr, you pipe it, and then, there's a
new command that I want you to learn which is
called more. more is the command which gives you
the output of a file one page at a time. So when
you do ls -ltr, pipe it, and more it, hit enter,
so now you will see one page at a time of all the
contents of etc directory, and at the bottom, it
does tell you that it's more. You hit spacebar to
go down to the second page, spacebar again,
spacebar again, wherever you are, you could quit
out of it by hitting Q, and you will get your
prompt back. Again, let's do up arrow key. Hit
enter, spacebar, spacebar, spacebar, spacebar to
go all the way down, you will keep hitting the
spacebar and get your prompt back. So that's how
you put in a pipe. You could also do a pipe to
have the output of a command and change its output
to a different way. Let's say if you want to do
ls, by the way, there's another command which is a
simple command if you want it to learn is ll,
which also gives you the result as if you are
doing ls -l. So you do ll, and you'd learn the
command more, which gives you one page at a time.
What if you want to get the last line of your
output, then you run ls -l, pipe it, and to get
the last line you will have to do tail -1.
It gives you the last line of your output. Now
tail is another command which is also a cool
command which will give you the last line or lines
of an output, which we'll cover later on. So this
is what the pipe is. I want you to try with
different commands, learn about pipe. I'm not sure
if there is a man page for pipe because it's a
character, but let's see. Yeah, there is none. But
if you wanted to know more about pipe, I have some
documentation you could get it or you could of
course go look it up online to find out more about
pipes. The pipe is is very important for all are
lessons that we will be covering later on because
this is how we're going to combine our commands.
[No audio]