Hello, the beautiful people.
So in this video, we're going to be finishing off our discussion of the locate command.
And in particular, you're going to learn how to update the database using the update DB command.
And you're also going to learn in the process how to gain superuser privileges so administrator privileges
using the sudo command.
So this is going to be a very important lecture touching not only on how to make the most out of the
locate command, but also giving you an absolute nugget of information on how to gain administrative
privileges, which is such a useful thing to be able to do more higher level things on your system.
So by the end of this video, you're going to know how to update the database that the locate command
uses so that the locate command always gives you accurate and correct results.
And you'll also know how to run administrator commands using sudo.
So this is going to be a very important lecture.
Let's go ahead and jump right into it.
Okay.
So let's start learning about the update DB command, which is short for update database, how one name,
right.
So let's create a new file on our desktop.
So I'm going to move to our desktop and we're going to create a new file called Find Me Dot txt.
So we're going to use the touch command, find me txt and there we are.
We have a file called find me not txt on our desktop.
Now if I try and run the locate command because this find me file has been created before our database
has been updated.
The locate command won't be able to find it in the database.
So if I try locate find me not txt we see we get absolutely nothing back even though the file exists.
It's not been entered into the database yet and therefore the locate command can't find it by searching
the database.
Okay.
So to update the database, to add it to the database, we need to update the database and that's where
the update DB command comes in.
So if we try it, we'll notice that we actually get an error.
And the error says that the shell cannot open the actual database file.
And the reason for that is the update.
DB command requires administrator privileges in order to run, and we can see this by looking at the
main page for the update DB command and we see at the top of the update DB command that it is in the
system managers section.
It's in section eight of the manual and that means it requires elevated privileges in order to run.
And you can see here what I was saying about update DB being run daily.
So you can read more about that if you like.
But the important thing here is that it's in section eight of the manual and therefore requires administrator
privileges in order to run and refer back to the cheat sheet about the manual structure.
If that if you need a bit of a reminder of that and what the sections of the manual do, okay.
So how can we get the administrator privileges in order to run this command?
Well, to do that, you use the sudo command.
I'm not sure if it's pronounced pseudo or pseudo, but I, I like pseudo, so we'll stick with that.
So the pseudo command is very simple.
You just write it before any command you want to run as the administrator.
So I'm going to type update.
DB And that's it.
Okay.
Now when I do that, because we're trying to get administrator privileges, the pseudo command is going
to ask us for our password.
So I'm going to enter my password, which is the password I just use normally to log in to the Linux
computer, but you'll notice that we don't see any password being typed out.
Now, this is a security feature that's built into the shell that stops people from knowing the length
of your passwords.
And the reason is that if people know the length of your password, it makes cracking it so much easier.
So don't worry that you don't see any feedback.
Just type your password.
You type your password.
It is being accepted by the shell.
And when you've done that, press enter and we'll see that the shell will pause for a bit as it updates
the database.
And then we have our shell prompt back and which lets us know that the command has completed.
So now that we've updated our database, the Find Me file should be in the database now.
So let's try and see if the locate command can find it.
Let's type locate find me, find me dot text.
I want to press enter you'll see that.
Yep it did find it this time and it tells us that it's on our desktop and it's called Find Me Text and
we don't have to be on the desktop.
We could be in our, let's say in our documents folder and we can press print working directory.
We see that we're in our documents.
But if I do locate, find me anything like that.
You see, it comes up with slash home.
Slash is the ad slash desktop slash find me dot text.
So it tells us where the where the actual file is.
Now if we take a look at the database file as well, let's just head back to our desktop for a minute
and let's take a look at the database file.
So we use locate with the capital C option.
We can see that actually this has changed if I save that as database after txt.
So here we are.
We've got database before and database after.
If I open up database before we see that we have what, 16,008 directories, 144,853 files and whatever
else.
Now, if I try to open up afterwards, we can see here that we've got this is before 144,853 files,
afterwards 144,848 files.
So it looks like some files have actually been deleted or something like from the system.
And seven, how many got 7,590,826 bytes afterwards?
Yeah.
It actually looks as though since we last updated the database, some files have indeed been deleted.
So maybe there were some temporary files in operation or something like that.
But you can see that the size of the database does change when you update it.
But if I do that again, so if I do database after to take a look, there should be absolutely no difference
between these two.
So this is database after and I look at database after two and we'll see that they are actually exactly
the same.
So when you update the database, it does indeed change now because the update DB command needs administrator
privileges or root privileges in order to run, you can see why the existing and follow options exist
for the locate command.
So you can see why these ones exist.
You've got existing and follow there so that when you're waiting for your administrator to update the
database, you as a regular user can still get on with your work.
Even if you don't have administrator privileges.
You could just get on with your work while the administrator is, you know, probably catching up on
emails or something.
Pretty clever, right?
So you've learnt a lot about the locate command in the past few videos.
So let's just take a quick recap of what you've learned to make sure that you've got it all.
First of all, the locate command search is a database that's stored on your computer for the four files,
matching the pattern that you give it and returns a list of results.
And using a database is a very fast method of searching, but it requires that the database be updated
in order to give you a complete and correct list of results.
Now you can protect yourself against errors using the existing and follow options for the for the locate
command.
But that's not really the best solution.
The best thing to do is just to update the database using the update DB command, but this is done automatically,
daily as well.
Now in order to do that, it does require administrative administrative privileges or root privileges
or superuser privileges, whatever you want to call it.
And therefore, you need to use the sudo command, the sudo command in order to actually gain those
privileges.
So you enter your password and then the command is run as the administrator.
So in order to update the database, you don't just type update DB, you type sudo update DB, enter
your password and then the database is updated and then you can use the locate command from that point
on and know that your results will be 100% correct and up to date.
So locate is a fantastically useful command and I use it all the time.
It's a really quick command to use, but there's another command that doesn't require a database and
it can actually be way, way more powerful.
And it's called Find Command and we'll be covering that in the next video.
So it's amazing.
It really, really is cool.
You can do such powerful things with it and I can't wait to show you.
So for all that good stuff, I'll see you in the next video.