Find this so powerful. I wanted to share some more advanced find examples with you.
So let me show you.
To start with sudo find minus type F, which
is looking for files minus size plus 100m.
That's for files only that have a size bigger than 100 megabyte.
Then I'm using find etc exec grab
l student curly braces, backslash semicolon.
Now what is that? Well, this is something that you could do in another way as well, but it
is finding files in the etc directory and on these files it will run the command grep l student,
which means that it is going to find files that have the text student within the file.
Now we have one minus exec statement here. I'm going to open a second exec statement
and that is sudo CP curly braces. We are going to copy it to find contents.
And this time I don't want to see any error messages. And that's why I'm putting a togreat then dev null behind it.
Toogreat then dev null will suppress any error messages. And that goes for
a clean output. Very useful if you're expecting a lot of error messages.
One little problem. The directory find contents does not exist. So I'm going to use
control A again to move my cursor to the start of the command line.
And I'm using mkdir find mkdir p find contents to
create this directory before we run the actual find command.
And oh boy, what do we see here? We see a missing argument to exec.
Does that make sense? Yes, because every exec needs to be closed with a semicolon.
So let me put the semicolon to close the exec that I have right here and run it
again there. We can see that it has done what I asked it to do. Is that so?
Well, LS l on find contents should show and yeah, that is so the files are right here.
Now another example is find again sudo find etc.
We start our find operation in the etc directory
name which is looking for all files minus type
f, which goes for files only.
This time I'm going to use xargs.
We'll use the output of the find command to be used as input for the grep command.
I Want to grep on 127001 or whatever text you want to use for
the grep and oh boy, now I'm getting all my error messages. Yeah, that
does make sense because I never used sudo in front of the xargs.
And here we see the result. Well, find first finds files based on all the different properties
of the files and then within these files it's going to use the grep utility, which is
the filtering utility which is checking to see if the text 127001 exists in inside the file.
One more example with find and printf this time so sudo find etc name
I'm looking for vals that have a name ending in any and printf.
I want to do some nice formatting for
these percent s comma percent b n and
then I'm closing my printf string.
Hey, let's also sort that. I'll tell you more about sort later, but
here we can see how the output is actually nothing at all.
Oh boy. Well maybe I should use name instead of ini.
There we can see the different properties that are printed
with this printf command and formatted in nice columns.
That's the end of this video about some advanced usage of the find utility.