Difference between find and locate command.
Now, we recently learned what how we could use find command and how we could use, locate command to
find the files as usually people forget once they created.
So now we need to in this lesson, we will learn what is the exact difference between find a locate
command, why we would use one and not use the other or vice versa.
So Locate Command uses a pre-built database which should be regularly updated while Fine Command iterates
over a file system to locate files.
Thus locate is much faster than fine, but can be inaccurate if the database can be seen as a cache
is not updated.
So in simple words, the difference between locate and find command is locate command has a database
that it maintains.
So if that database updated and then you try to find it using the locate command, then it will be the
search result is going to be a lot faster.
Whereas Flying Command is actually relies on filesystem to do the searches.
It does not have a database.
That is the main differences between these two commands.
To have the the database updated.
Whenever a new files are created, then you have to run the command update DB or if you do not run this
command, then by default, perhaps after a few minutes or hours that the system or the operating system
will run or update the locate command database itself.
But if you do not want to wait and you wanted to get the result right away, then of course you have
to run the update DB Command.
Now, further, without further ado, let's get into our Linux machine and I'll show you exactly what
is the difference between both of these commands that we have learned in the previous lesson.
I'll go straight into my Linux machine.
I am logged in as myself and my host name is my first Linux VM.
OK, so now if I create a file, let's say touch and let's call it Susan.
And hit enter.
Now, where am I?
Which territory am I in?
So you do?
I am in my home.
I have subdirectory.
OK, perfect.
Now if I wanted to find the file, I would run the command, find DOT, meaning this current location,
Dasch name Susan and hit Enter and now is telling you the Susan file is in this current directory.
You could also do the same thing if you could specify the flight path or absolute path which is home
I afsal and then you hit enter.
Then it tells you that this Susan file is located in my office.
So if you run the locate, come in on, Susan.
You think what will happen here, it will not find it.
Why?
Because the locate command relies on its own database, a local database, and that database is not
updated yet.
So for that database to know, hey, there is a new file that has just been created called Susan, you
need to know about it, then what we need to do is we need to run the command update.
DB When you run that, you will get that error message saying update data.
DB cannot open a temporary file for war.
Let em locate em.
Locate D.B. By the way, this is the actual database file where all the files information on the file
system are stored.
So it's saying it cannot update Y because or it cannot find it or cannot open it because we are not
root.
So become root.
And now run update divi, it has completed exit out of route, make sure now you are yourself.
Now you run the locate command on Susan and hit enter and there you go.
It finds it.
It finds it so fast.
So locate the man.
You do not have to specify the path where it has to go and look for.
You do not have to specify the options.
Dash name.
It's that simple.
You will run locate command followed by the name of the file that you're looking for and it will find
it in the split of a second for you.
That's why locate command search is a lot faster.
However, it relies on the database for.
So make sure every time you create a file and you want to do a locate comment on that file, run the
command update database.
So that's the main difference that I wanted to cover in this lesson.
I know I had a lot of people, a lot of students asked me about define and locate command.
So I added this lesson for you guys.
So there is no confusion about it.
And now you know everything about these two commands.
All right, enjoy.