1 00:00:00,330 --> 00:00:01,800 Hello, the beautiful people. 2 00:00:01,800 --> 00:00:06,510 So in this video, we're going to be finishing off our discussion of the locate command. 3 00:00:06,510 --> 00:00:12,480 And in particular, you're going to learn how to update the database using the update DB command. 4 00:00:12,480 --> 00:00:18,840 And you're also going to learn in the process how to gain superuser privileges so administrator privileges 5 00:00:18,840 --> 00:00:20,520 using the sudo command. 6 00:00:20,530 --> 00:00:25,290 So this is going to be a very important lecture touching not only on how to make the most out of the 7 00:00:25,290 --> 00:00:30,780 locate command, but also giving you an absolute nugget of information on how to gain administrative 8 00:00:30,780 --> 00:00:36,420 privileges, which is such a useful thing to be able to do more higher level things on your system. 9 00:00:36,420 --> 00:00:39,990 So by the end of this video, you're going to know how to update the database that the locate command 10 00:00:39,990 --> 00:00:44,040 uses so that the locate command always gives you accurate and correct results. 11 00:00:44,040 --> 00:00:47,430 And you'll also know how to run administrator commands using sudo. 12 00:00:47,430 --> 00:00:49,200 So this is going to be a very important lecture. 13 00:00:49,200 --> 00:00:50,880 Let's go ahead and jump right into it. 14 00:00:52,230 --> 00:00:52,550 Okay. 15 00:00:52,590 --> 00:00:58,740 So let's start learning about the update DB command, which is short for update database, how one name, 16 00:00:58,740 --> 00:00:59,100 right. 17 00:00:59,100 --> 00:01:02,040 So let's create a new file on our desktop. 18 00:01:02,040 --> 00:01:07,980 So I'm going to move to our desktop and we're going to create a new file called Find Me Dot txt. 19 00:01:07,980 --> 00:01:11,940 So we're going to use the touch command, find me txt and there we are. 20 00:01:11,940 --> 00:01:14,940 We have a file called find me not txt on our desktop. 21 00:01:15,210 --> 00:01:25,440 Now if I try and run the locate command because this find me file has been created before our database 22 00:01:25,440 --> 00:01:26,640 has been updated. 23 00:01:26,940 --> 00:01:30,010 The locate command won't be able to find it in the database. 24 00:01:30,010 --> 00:01:36,930 So if I try locate find me not txt we see we get absolutely nothing back even though the file exists. 25 00:01:37,380 --> 00:01:43,230 It's not been entered into the database yet and therefore the locate command can't find it by searching 26 00:01:43,230 --> 00:01:43,860 the database. 27 00:01:43,890 --> 00:01:44,260 Okay. 28 00:01:44,340 --> 00:01:50,010 So to update the database, to add it to the database, we need to update the database and that's where 29 00:01:50,010 --> 00:01:53,640 the update DB command comes in. 30 00:01:53,640 --> 00:01:57,330 So if we try it, we'll notice that we actually get an error. 31 00:01:57,330 --> 00:02:02,400 And the error says that the shell cannot open the actual database file. 32 00:02:02,400 --> 00:02:04,140 And the reason for that is the update. 33 00:02:04,140 --> 00:02:09,150 DB command requires administrator privileges in order to run, and we can see this by looking at the 34 00:02:09,150 --> 00:02:17,460 main page for the update DB command and we see at the top of the update DB command that it is in the 35 00:02:17,460 --> 00:02:19,110 system managers section. 36 00:02:19,110 --> 00:02:26,070 It's in section eight of the manual and that means it requires elevated privileges in order to run. 37 00:02:26,070 --> 00:02:30,060 And you can see here what I was saying about update DB being run daily. 38 00:02:30,060 --> 00:02:32,250 So you can read more about that if you like. 39 00:02:32,250 --> 00:02:36,960 But the important thing here is that it's in section eight of the manual and therefore requires administrator 40 00:02:36,960 --> 00:02:41,370 privileges in order to run and refer back to the cheat sheet about the manual structure. 41 00:02:41,370 --> 00:02:45,600 If that if you need a bit of a reminder of that and what the sections of the manual do, okay. 42 00:02:45,720 --> 00:02:51,180 So how can we get the administrator privileges in order to run this command? 43 00:02:51,270 --> 00:02:54,570 Well, to do that, you use the sudo command. 44 00:02:55,570 --> 00:03:01,920 I'm not sure if it's pronounced pseudo or pseudo, but I, I like pseudo, so we'll stick with that. 45 00:03:01,930 --> 00:03:04,870 So the pseudo command is very simple. 46 00:03:04,870 --> 00:03:09,070 You just write it before any command you want to run as the administrator. 47 00:03:09,070 --> 00:03:10,360 So I'm going to type update. 48 00:03:10,360 --> 00:03:11,800 DB And that's it. 49 00:03:11,800 --> 00:03:12,340 Okay. 50 00:03:12,430 --> 00:03:18,700 Now when I do that, because we're trying to get administrator privileges, the pseudo command is going 51 00:03:18,700 --> 00:03:20,920 to ask us for our password. 52 00:03:20,920 --> 00:03:25,870 So I'm going to enter my password, which is the password I just use normally to log in to the Linux 53 00:03:25,870 --> 00:03:29,950 computer, but you'll notice that we don't see any password being typed out. 54 00:03:29,950 --> 00:03:34,360 Now, this is a security feature that's built into the shell that stops people from knowing the length 55 00:03:34,360 --> 00:03:35,410 of your passwords. 56 00:03:35,410 --> 00:03:40,960 And the reason is that if people know the length of your password, it makes cracking it so much easier. 57 00:03:40,960 --> 00:03:42,700 So don't worry that you don't see any feedback. 58 00:03:42,700 --> 00:03:43,900 Just type your password. 59 00:03:44,110 --> 00:03:44,830 You type your password. 60 00:03:44,830 --> 00:03:46,600 It is being accepted by the shell. 61 00:03:46,600 --> 00:03:54,070 And when you've done that, press enter and we'll see that the shell will pause for a bit as it updates 62 00:03:54,070 --> 00:03:55,030 the database. 63 00:03:55,030 --> 00:03:59,650 And then we have our shell prompt back and which lets us know that the command has completed. 64 00:03:59,650 --> 00:04:04,810 So now that we've updated our database, the Find Me file should be in the database now. 65 00:04:04,810 --> 00:04:07,930 So let's try and see if the locate command can find it. 66 00:04:07,960 --> 00:04:13,180 Let's type locate find me, find me dot text. 67 00:04:13,180 --> 00:04:14,950 I want to press enter you'll see that. 68 00:04:14,950 --> 00:04:20,200 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 69 00:04:20,200 --> 00:04:21,519 we don't have to be on the desktop. 70 00:04:21,519 --> 00:04:27,670 We could be in our, let's say in our documents folder and we can press print working directory. 71 00:04:27,670 --> 00:04:28,960 We see that we're in our documents. 72 00:04:28,960 --> 00:04:33,460 But if I do locate, find me anything like that. 73 00:04:33,480 --> 00:04:35,410 You see, it comes up with slash home. 74 00:04:35,410 --> 00:04:39,430 Slash is the ad slash desktop slash find me dot text. 75 00:04:39,430 --> 00:04:43,060 So it tells us where the where the actual file is. 76 00:04:43,060 --> 00:04:48,340 Now if we take a look at the database file as well, let's just head back to our desktop for a minute 77 00:04:49,420 --> 00:04:51,250 and let's take a look at the database file. 78 00:04:51,250 --> 00:04:53,620 So we use locate with the capital C option. 79 00:04:54,790 --> 00:05:03,400 We can see that actually this has changed if I save that as database after txt. 80 00:05:03,490 --> 00:05:04,270 So here we are. 81 00:05:04,270 --> 00:05:06,190 We've got database before and database after. 82 00:05:06,190 --> 00:05:15,580 If I open up database before we see that we have what, 16,008 directories, 144,853 files and whatever 83 00:05:15,580 --> 00:05:15,820 else. 84 00:05:15,820 --> 00:05:23,020 Now, if I try to open up afterwards, we can see here that we've got this is before 144,853 files, 85 00:05:23,020 --> 00:05:26,410 afterwards 144,848 files. 86 00:05:26,410 --> 00:05:31,210 So it looks like some files have actually been deleted or something like from the system. 87 00:05:31,360 --> 00:05:39,490 And seven, how many got 7,590,826 bytes afterwards? 88 00:05:39,910 --> 00:05:40,750 Yeah. 89 00:05:40,750 --> 00:05:46,570 It actually looks as though since we last updated the database, some files have indeed been deleted. 90 00:05:47,050 --> 00:05:50,140 So maybe there were some temporary files in operation or something like that. 91 00:05:50,140 --> 00:05:54,400 But you can see that the size of the database does change when you update it. 92 00:05:55,240 --> 00:06:02,680 But if I do that again, so if I do database after to take a look, there should be absolutely no difference 93 00:06:02,680 --> 00:06:03,880 between these two. 94 00:06:03,880 --> 00:06:11,260 So this is database after and I look at database after two and we'll see that they are actually exactly 95 00:06:11,260 --> 00:06:11,920 the same. 96 00:06:12,400 --> 00:06:20,170 So when you update the database, it does indeed change now because the update DB command needs administrator 97 00:06:20,170 --> 00:06:26,740 privileges or root privileges in order to run, you can see why the existing and follow options exist 98 00:06:26,740 --> 00:06:27,610 for the locate command. 99 00:06:27,610 --> 00:06:29,290 So you can see why these ones exist. 100 00:06:29,620 --> 00:06:35,080 You've got existing and follow there so that when you're waiting for your administrator to update the 101 00:06:35,080 --> 00:06:38,980 database, you as a regular user can still get on with your work. 102 00:06:39,370 --> 00:06:42,610 Even if you don't have administrator privileges. 103 00:06:42,610 --> 00:06:47,080 You could just get on with your work while the administrator is, you know, probably catching up on 104 00:06:47,080 --> 00:06:48,040 emails or something. 105 00:06:48,040 --> 00:06:49,000 Pretty clever, right? 106 00:06:50,060 --> 00:06:53,090 So you've learnt a lot about the locate command in the past few videos. 107 00:06:53,090 --> 00:06:57,020 So let's just take a quick recap of what you've learned to make sure that you've got it all. 108 00:06:57,110 --> 00:07:02,930 First of all, the locate command search is a database that's stored on your computer for the four files, 109 00:07:02,930 --> 00:07:06,710 matching the pattern that you give it and returns a list of results. 110 00:07:06,710 --> 00:07:13,070 And using a database is a very fast method of searching, but it requires that the database be updated 111 00:07:13,070 --> 00:07:16,420 in order to give you a complete and correct list of results. 112 00:07:16,430 --> 00:07:23,660 Now you can protect yourself against errors using the existing and follow options for the for the locate 113 00:07:23,660 --> 00:07:24,050 command. 114 00:07:24,050 --> 00:07:25,670 But that's not really the best solution. 115 00:07:25,670 --> 00:07:31,820 The best thing to do is just to update the database using the update DB command, but this is done automatically, 116 00:07:31,820 --> 00:07:33,110 daily as well. 117 00:07:33,110 --> 00:07:38,090 Now in order to do that, it does require administrative administrative privileges or root privileges 118 00:07:38,090 --> 00:07:40,670 or superuser privileges, whatever you want to call it. 119 00:07:40,670 --> 00:07:46,850 And therefore, you need to use the sudo command, the sudo command in order to actually gain those 120 00:07:46,850 --> 00:07:47,390 privileges. 121 00:07:47,390 --> 00:07:50,780 So you enter your password and then the command is run as the administrator. 122 00:07:50,780 --> 00:07:56,240 So in order to update the database, you don't just type update DB, you type sudo update DB, enter 123 00:07:56,240 --> 00:08:01,310 your password and then the database is updated and then you can use the locate command from that point 124 00:08:01,310 --> 00:08:04,940 on and know that your results will be 100% correct and up to date. 125 00:08:05,120 --> 00:08:09,920 So locate is a fantastically useful command and I use it all the time. 126 00:08:09,920 --> 00:08:14,270 It's a really quick command to use, but there's another command that doesn't require a database and 127 00:08:14,270 --> 00:08:16,820 it can actually be way, way more powerful. 128 00:08:16,820 --> 00:08:20,450 And it's called Find Command and we'll be covering that in the next video. 129 00:08:20,450 --> 00:08:21,680 So it's amazing. 130 00:08:21,680 --> 00:08:22,790 It really, really is cool. 131 00:08:22,790 --> 00:08:25,220 You can do such powerful things with it and I can't wait to show you. 132 00:08:25,220 --> 00:08:28,340 So for all that good stuff, I'll see you in the next video.