Hello the beautiful people.
And welcome back.
So let's go ahead and make our work with the find command.
Totally extreme.
Okay.
So let's just go ahead and create a folder on our desktop called Haystack.
Okay.
So there it is that's appeared.
And what we're going to do in here is we're going to make 500 folders.
Now, I want to see if you can remember how to do this.
If you can remember how to use brace expansion to create 500 folders that are called folder one, folder
two, folder three all the way up until folder 500.
So go ahead and pause a video.
Now try and use brace expansion to make folder one to folder 500 inside of the haystack folder and then
come back to see how you got on.
How'd you get on?
Did you manage it?
If so, great memory.
If not, don't worry.
It's been a while.
So let's actually try and see if we can do this right.
What we're going to do is we're going to do make directory haystack slash folder 1.. 500.
So this is saying make folder 1 to 500 inside the haystack folder.
When I press enter and we look in Haystack, we've got 100 folders in there and I probably should change
the layout.
There we go.
Folder one two, folder 500.
Try doing that with your mouse and pointing and clicking it will take you forever.
So there we go.
We've done that.
Now in each of those folders, we need to make 100 files.
100 files in 500 folders.
That's right.
And it's actually not difficult to do at all.
So challenge number to see if you can remember how to use the touch command with brace expansion to
create 100 files called file one, file to file three all the way until file 100 in each of the 500
folders.
So go ahead and give that a go and then come back to see how you did.
All right.
How did you do that?
That was a bit harder.
Hopefully you got it.
If not, don't worry.
This is how I would have gone about doing it.
So I'd use the touch command, because that's what we use to create files.
And I'd say, okay, in the haystack folder, in folder 1 to 500, I want you to make file 1 to 100.
So if I go ahead and do that, we shall see that inside each of these folders.
Now, we should have 100 files.
So there we are.
There's folder one now has file one, two, 100.
If I pick another one here, folder 26, file 1 to 100 and so on.
If we go all the way down to folder 402, that's got it own 100 files.
So you can really start seeing now how powerful the shell is when you got all these different pieces
that you can use together.
Now what we've done is we've made a folder called Haystack.
500 folders in each of those 100 files.
So it's about 50,000 files, if my math is all right.
So now what we're going to do is I'm going to just type something here.
It's a don't worry about how it works, but I'm going to type a bit a bit of code here that's going
to create in one of the run, in one of the folders, in one of the folders from 1 to 500.
Um, what we're going to do is we're going to find a file and we're going to make a file called needle
txt.
So what this is saying is touch inside a random folder.
It can be folder 1 to 500.
Any random number in there file called needle dot txt.
So we've created a file called needle that txt in somewhere in the haystack.
But we don't know where.
And it's our job now to use the find command in order to find it.
So how can we find the needle?
Let's have a thing through this.
Clear the screen and maximize it.
So let's just take a look how we might do this.
So first of all, we're going to use the find command and we're going to start.
Where are we going to start?
We probably start with the haystack folder.
Okay.
We know it's in the haystack.
So we're going to start searching from that point.
And we know that it's a file, right?
So we don't need to look at all the directories, but remembering that the find command will by default
list out files and directories.
So we're going to worry about searching through all the searching and returning folders.
Let's just look for files and we know that its name is needle dot txt don't we.
Okay.
So if we do that and press enter, let's see if it works.
And it has.
It's found needle dot txt inside folder 449.
So how awesome is that?
Right.
We've managed to find the needle in the haystack, but now let's try and move it to our desktop.
Okay.
So to do that, now that we've got the result, we will use the exec option to execute something on
it.
Now to move something.
Remember, you would type move then what you want to move and where you want to move it to.
And remember, of course, we've got to end everything with a backslash semicolon.
Okay?
This is how you end the exit option.
So we are we're going to move something to somewhere.
Now we want to move it onto our desktop.
So let's just put a tilde slash desktop.
Okay?
So that is our desktop.
That's where we're going to move it.
And what are we going to move?
Well, that file so we just put a square, a set of squiggly brackets and it works the same for one
file as it would for 100,000.
So fingers crossed.
If we go ahead and do that, we press enter.
And now if I just close the terminal and have a look on our desktop, we've actually done it.
We've managed to move needle dot text all the way from somewhere inside that haystack of potentially
50,000 files.
Find it and move it to our to move it to our desktop.
So that's just how awesome what you've learned in the past few videos can be.
So what you've seen in the past few videos is that the fine command is a total beast of a command.
You've seen it do so many, so very many things with it.
But the main key point I'm just going to go through in a quick summary.
So the fine command can be used to execute sophisticated search tasks.
You've also seen that you've seen how to use the locate command, and that's very good for just quick,
quick like searches.
But if you want to do something very sophisticated, the find command is what you're going to want to
use.
First of all, it doesn't use a database, whereas the locate command does the find command works directly
on your file system, which means that it's always going to be correct, but it might be slightly slower.
So that's just something to bear in mind.
And the fine command allows you to build up search queries where you can search by the name of the file,
the type of the thing that you're searching for, the size and so much more.
Okay.
You can see examples of those in the man page, just type man, then find and you'll be able to read
the manual page for the fine command.
There's just so much that it can do.
Okay.
And once you've got this big list of results, you can use the exec option to execute another command
on each of those results.
Just remember to end that with the backslash, then a semicolon.
And if you're working with a small number of files and you're doing something potentially destructive
like deleting or removing or something like that or moving files, then, you know, use the OC option
instead because then it will prompt you to say, is this one okay or is this okay?
Or Is this okay?
And you've got to authorize it every time.
I guess that's something to to bear in mind as well.
Now, after what you've learned in the from the last few days about the fine command, everything else
that you're going to learn in the next few videos is going to seem really like a breeze.
Okay.
So in the next video, I'm going to be showing you how to open files on the command line and read what's
inside them.
And I'll also be making plenty of kitten jokes.
So for all that good stuff, I'll see you in the next video.