- In the previous video,
you have learned how to work with find,
and you have seen that find is pretty powerful.
If you think that's all, well, I have a few more commands
that I would like to discuss.
For your convenience, I put them on the slide right here,
and I'm going to run them for you.
Oh, and just a tip,
you better run them with sudo privileges,
at least most of them.
Let's go.
So let me start with sudo find /
minus type f.
Minus type f is looking for items that are of the type f,
which is ordinary files.
Minus size, +100M, which is showing files with a size
bigger than 100M.
Only files.
The thing here is that if in find you are going to look
for specific items, you don't want to see any directories
or whatever, so this is looking for files only.
Second example is sudo find
/etc -exec
grep -l student.
Based on what we have done before, you should be able
to identify what this is doing.
This is looking for files in /etc, and in these files,
it will use grep -l student,
which means that it is looking in the file contents
to see if the text student occurs
somewhere in the file contents.
And next I want to run a second -exec,
and yes, that is something that you can do.
Second -exec cp, we are going to copy these files.
Curly braces to, well, let's copy it to /root/linda
because that's an existing directory, backslash semicolon.
The point here is that I wanna show you
that you can use multiple exec statements
on one find command.
And this is how you do it.
Now the third one is find /etc
minus name, star.
I wanna find all files, -type f.
Notice that you might as well drop -name star
because if you dropped it, then it'll find all files also.
Then I'm going to use xargs.
Xargs is an alternative way
for sending the output of the find command
to another command.
And the xargs this time is going to look
for the occurrence of the text grep 127.0.0.1.
And there we go.
And oh, too many error messages.
Let me use 2>/dev/null again so that we don't have to look
at the error messages,
and we only see what is being produced.
Now hey, this is interesting.
Do you see what's happening here?
I still see error messages.
And you know why?
Well, that's because of the pipe.
I'm using the pipe here.
Before the pipe, we have the find command.
After the pipe, we have the xargs command.
It is not xargs that is generating all of these errors.
It's find that is generating all of these errors,
or maybe it's even worse, and maybe it's both of them.
And if I don't want to see any errors anymore,
then I also need 2> to /dev/null before the pipe.
And now we can only see the result.
And the result is a list of files
that contain the text 127.0.0.1.
Now you can also do some formatting in find.
Now let me do find /etc
minus name,
*conf.
And there we go.
We have configuration files.
Now this is what we see by default.
And the nice thing is that find allows you
to do some formatting on that.
So if I add -printf,
the -printf allows me to do formatting.
And in this formatting, I am going to specify how I want it
to be printed, %s, comma,
%p\n, closing quote,
which is doing what?
This is giving me additional information.
And as you can see, I get information
about the size of the file in the first column,
and then I have the name of the file.
And it's separated with a comma and a space.
And if you want to, you can even sort that.
That's a new utility that we will discuss
in more detail later.
Sort -rn, which is doing a reverse numeric sort,
so that you have the biggest file on the top
and the smallest file on the bottom.
And that is how you can use find in a more advanced way.