Hello the beautiful people.
And welcome to this video where you're going to be learning about one of the most useful and most important
commands on all of Linux, the fine command.
Now, the fine command is used to execute sophisticated search tasks on your file system, and there
is so much stuff that you can do with the fine command that we're going to break up our discussion into
a few videos.
And in the next few videos, what you're going to learn is you're going to learn how to use the find
commands.
So what the find commands default behavior is you can learn how to control the search depth that the
find commands searches on your file system.
You can learn how to search by type.
So how to get the find the find to command to only return files or directories, head to search by name.
So if you know exactly what you're looking for, you can search by name and how to search by file size.
So you can say, Hey, find command, find me all the files that are bigger than five megabytes or smaller
than ten kilobytes, for example, or something in between.
And one of the really cool things about the Find Command is that once you get this big list of results,
as you'll see in the videos, you can execute other commands or the pipelines on each of those results.
So we're going to show you how to do that.
And you're going to have a really powerful tool in your Linux toolkit for manipulating loads of files
at once.
It's going to be awesome.
So by the end in general, you're going to be able to perform sophisticated search tasks with the find
command.
So that's it in a nutshell.
And you're going to want to pay attention to this section for sure, because this may be very useful
for your assignment.
Hint, hint.
So I hope you enjoy it.
Let's go ahead and jump over into Ubuntu and start playing with the find command.
All right, so here we are in our home directory.
So let's just go ahead and see how the find command will work by default.
So the default behavior of the find command, if we just go ahead and run find is to list every single
file and every single folder that is lower down in our file system than the current folder that we're
in.
Okay.
And everything inside the folder that we're in.
Okay.
So because we're currently in our working directory, if I just hit, if I just type, find and press
enter, we see a big long list of every single file and every single folder that is in our home directory
and below it.
So it will go into every folder, every hidden folder and expand out and expand out and expand out and
list everything.
So for example, here we've got our pictures folder.
It will not just show our pictures folder, it will also show that we have a folder inside the pictures
folder called Holiday.
We just have a file inside the pictures folder called Find Me 60 txt for example, we've got our desktop,
we've got find me one point txt and our desktop itself videos and our videos find me three point txt.
So I'll list out the folders and everything inside them.
And if there are folders inside those folders then it will do exactly the same.
It will go into those folders, expand those out, and if there's other folders in there, it will go
into those folders and expand it out to an infinite depth.
It will just go as deep as possible into your file system from starting where starting in the current
directory.
So this is an immediate difference for us between the locate command and the find command.
So the find command will list out files and folders, but the locate command will only list files and
the find command does not need a database in order to work.
The find command just works right there and then.
So it's always up to date because it operates directly on your file system.
It doesn't use a database, so it's always up to date.
But the one downside of that is it's slightly slower than using a database.
So that's a trade off to bear in mind.
So because the find command will list every single file below where you give it, you can actually also,
for example, give it the the slash folder, the base folder for the entire system.
And this will list every single file and every single folder on the entire system.
So that's a fun thing to try if you're bored and you potentially want to smash your computer.
But you know, if you give it find slash Etsy, then it will list everything on the system below Etsy.
And you can see it's giving us files and folders.
If I give it, find, slash home, slash Ziad, slash documents, for example, it will list out everything
below the documents folder so we can see that it's given us the documents folder and the find me to
txt inside there.
And if I, if I make it our documents folder, if I make another folder, let's call it blah blah,
let's just call it that and copy and paste into there.
We're going to call it we're going to call this one test.
TXT Now if I do find again with the documents folder file at home slash z, let's just do this, let's
do the tilde.
Okay.
What's going to happen here is you'll see now that it's done the done the blah folder as well and it's
gone into the blah folder to find test dot txt.
So it said we sold it, look in the documents folder it listed out find me two and it saw another folder
here called blah and it opened that and listed everything out inside there.
If I make another folder called blah blah and inside there I copy and paste it.
So it says Test two.
Text.
And now I just say, find everything in the documents folder.
You'll see that it's also listing out blah blah and test two.
So the final command is searching deeper and deeper and deeper into the file system to an infinite depth.
So that's something to bear in mind.
And it starts either with the current directory.
So I can start at the home directory, which is where we are at the minute or wherever you give it.
So if I'm start to tell it to start at the documents folder, it will start there and continually dig
deeper into the file system until it's shown you every file and every folder.
No matter whether they're hidden or not, it doesn't matter.
It'll show you every file in every folder deeper than that point on the file system.
So just to make this clear, if I go to the documents folder because I'm currently in the documents
folder, as you can see by the P command, if now I just run the find command because the find command
will start by default at the folder we're currently in.
If I do that and you can see now that it is started listing out the same stuff as up here, it's solid.
Solid as that.
We've got the blah folder, the blah blah blah and it's going into showing us test two and test and
find me to exactly what we were getting in our documents folder up here because we were in the documents
folder when we ran the find command.
So you can either be in the directory that you want to start searching from or if you're not, for example,
we're not in the slash e.t.c. folder.
We can start the search from there and it will search from the EDC folder and continue to go to an infinite
depth from that point.
So that's what the Find Command is.
It doesn't use a database, it operates directly on your file system.
So it's a bit slower than the locate command, but it's incredibly powerful.
So now that you've understood the basics of what the Find Command does in the next video, we're going
to show you how you can customize some of its behavior, starting with how you can control can control
the depth to which it's searches and what it searches for.
So the fine command search is from where you give it or from the current directory by default.
And in the next video, we're going to take a look at how you can control some of the way that it searches.
So I'll see you in the next video.