In this video, you'll learn about GREP.
GREP is probably one of the most important utilities in Linux.
It's a very powerful filtering utility.
And it's an excellent way to find text in files or in output.
PSAOX pipe GREP SSH is looking for the text SSH
in the output of the PS command.
And there's a couple more.
Let me just pop them on the slide and show it for you.
So PSAOX, we have already seen it, right?
GREP SSH is showing that I have SSHD up and running.
Now, if you're GREP-ing the output of PS,
you will always see the GREP command itself as well.
Because the GREP command was running at the moment
that you checked PSAOX, and it has found itself.
Now, if you don't want to see that,
then I would suggest you use another pipe
and add GREP minus VGREP to it.
That's the exclude option.
Show me everything apart from lines that contain
the text GREP themselves.
I also like PSFAOX, which is showing the process forest.
It's a hierarchical relation where
you can see that PSFAOX is a child of the bash shell.
And this bash shell is a child of sudo minus I.
And apparently, I did sudo minus I twice.
And that is convenient.
Now, let's imagine that you are looking for some output
where you want to see that in an easy way.
Then GREP minus B for before, minus B5, bash,
is showing lines that contain the text bash,
but also the five lines in front of it.
And that might be very helpful to show you
some contextual information.
Next, I can use GREP Linda on star.
Does that make sense?
Well, that doesn't make sense for multiple reasons.
Reason number one, it's complaining about directories.
Is it directory?
Reason number two, do I even have a use of Linda?
Yeah, I do have use of Linda.
Well, that makes it easier and probably
makes that if we do this from the ETC directory,
it will work.
So GREP Linda on star is showing all files
that contain the text Linda.
And, oh, again, these nasty error messages.
Is it directory?
Well, you know what to do about it.
Just add toGREP then dev null to the command.
And then you have the clean result. And in this result,
we see the file name, including the matching line.
Now, maybe you just want to see the file name and not
the matching line.
Then you add the minus L option, which
is just listing the file names.
Also convenient might be the I for case insensitive.
Doesn't make a difference in this case, by the way.
And you can look for contextual information in files as well.
So let me do GREP minus I root.
I want it to be case insensitive.
Minus A5 in ETC SSH, SSH D underscore config.
That's a configuration for a secure shell server.
We talk about that later.
And what do we see?
We see lines that have a root.
Case insensitive, and that seems to be good.
And we see the five lines that are following as well.
Now that we have talked about minus A and minus B,
let me also tell you about minus C,
which is showing five lines after, as well as
five lines before.
Now, final thing I want to show you is GREP minus R root
in star to greater than dev null.
What is this minus R?
Minus R is recursive, so including subdirectories.
And oh boy, this is what we call too much information.
Maybe we just want to list the names of these files.
There you go.
And here we have all these file names.
That's all for GREP for now.
In the next video, you'll learn about the magic
that you can add to it by using regular expressions.