1 00:00:00,930 --> 00:00:02,160 Hello the beautiful people. 2 00:00:02,160 --> 00:00:02,960 And welcome back. 3 00:00:02,969 --> 00:00:06,210 So let's go ahead and make our work with the find command. 4 00:00:06,600 --> 00:00:07,890 Totally extreme. 5 00:00:07,920 --> 00:00:08,220 Okay. 6 00:00:08,250 --> 00:00:14,820 So let's just go ahead and create a folder on our desktop called Haystack. 7 00:00:15,060 --> 00:00:15,630 Okay. 8 00:00:15,630 --> 00:00:16,890 So there it is that's appeared. 9 00:00:16,890 --> 00:00:21,180 And what we're going to do in here is we're going to make 500 folders. 10 00:00:21,180 --> 00:00:23,420 Now, I want to see if you can remember how to do this. 11 00:00:23,440 --> 00:00:30,900 If you can remember how to use brace expansion to create 500 folders that are called folder one, folder 12 00:00:30,900 --> 00:00:35,100 two, folder three all the way up until folder 500. 13 00:00:35,310 --> 00:00:36,420 So go ahead and pause a video. 14 00:00:36,420 --> 00:00:42,390 Now try and use brace expansion to make folder one to folder 500 inside of the haystack folder and then 15 00:00:42,390 --> 00:00:43,860 come back to see how you got on. 16 00:00:49,300 --> 00:00:49,810 How'd you get on? 17 00:00:49,810 --> 00:00:50,470 Did you manage it? 18 00:00:50,500 --> 00:00:52,020 If so, great memory. 19 00:00:52,030 --> 00:00:53,110 If not, don't worry. 20 00:00:53,110 --> 00:00:53,890 It's been a while. 21 00:00:54,310 --> 00:00:56,420 So let's actually try and see if we can do this right. 22 00:00:56,440 --> 00:01:05,530 What we're going to do is we're going to do make directory haystack slash folder 1.. 500. 23 00:01:05,920 --> 00:01:09,430 So this is saying make folder 1 to 500 inside the haystack folder. 24 00:01:09,430 --> 00:01:17,020 When I press enter and we look in Haystack, we've got 100 folders in there and I probably should change 25 00:01:17,020 --> 00:01:17,410 the layout. 26 00:01:17,410 --> 00:01:18,040 There we go. 27 00:01:18,040 --> 00:01:21,100 Folder one two, folder 500. 28 00:01:21,280 --> 00:01:25,570 Try doing that with your mouse and pointing and clicking it will take you forever. 29 00:01:25,570 --> 00:01:26,560 So there we go. 30 00:01:26,560 --> 00:01:26,980 We've done that. 31 00:01:26,980 --> 00:01:31,810 Now in each of those folders, we need to make 100 files. 32 00:01:32,440 --> 00:01:34,660 100 files in 500 folders. 33 00:01:34,660 --> 00:01:35,290 That's right. 34 00:01:35,290 --> 00:01:37,090 And it's actually not difficult to do at all. 35 00:01:37,090 --> 00:01:43,450 So challenge number to see if you can remember how to use the touch command with brace expansion to 36 00:01:43,450 --> 00:01:52,390 create 100 files called file one, file to file three all the way until file 100 in each of the 500 37 00:01:52,390 --> 00:01:53,020 folders. 38 00:01:53,290 --> 00:01:57,160 So go ahead and give that a go and then come back to see how you did. 39 00:02:02,430 --> 00:02:02,900 All right. 40 00:02:02,910 --> 00:02:03,500 How did you do that? 41 00:02:03,510 --> 00:02:04,560 That was a bit harder. 42 00:02:05,070 --> 00:02:05,810 Hopefully you got it. 43 00:02:05,820 --> 00:02:06,960 If not, don't worry. 44 00:02:06,960 --> 00:02:08,850 This is how I would have gone about doing it. 45 00:02:09,210 --> 00:02:12,450 So I'd use the touch command, because that's what we use to create files. 46 00:02:12,450 --> 00:02:21,180 And I'd say, okay, in the haystack folder, in folder 1 to 500, I want you to make file 1 to 100. 47 00:02:21,480 --> 00:02:27,750 So if I go ahead and do that, we shall see that inside each of these folders. 48 00:02:27,750 --> 00:02:29,850 Now, we should have 100 files. 49 00:02:29,850 --> 00:02:30,330 So there we are. 50 00:02:30,330 --> 00:02:32,770 There's folder one now has file one, two, 100. 51 00:02:32,790 --> 00:02:37,640 If I pick another one here, folder 26, file 1 to 100 and so on. 52 00:02:37,650 --> 00:02:41,520 If we go all the way down to folder 402, that's got it own 100 files. 53 00:02:41,880 --> 00:02:47,520 So you can really start seeing now how powerful the shell is when you got all these different pieces 54 00:02:47,520 --> 00:02:48,740 that you can use together. 55 00:02:49,170 --> 00:02:52,510 Now what we've done is we've made a folder called Haystack. 56 00:02:52,530 --> 00:02:56,190 500 folders in each of those 100 files. 57 00:02:56,910 --> 00:02:59,970 So it's about 50,000 files, if my math is all right. 58 00:03:00,360 --> 00:03:03,420 So now what we're going to do is I'm going to just type something here. 59 00:03:03,420 --> 00:03:09,450 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 60 00:03:09,450 --> 00:03:17,520 to create in one of the run, in one of the folders, in one of the folders from 1 to 500. 61 00:03:18,250 --> 00:03:23,760 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 62 00:03:24,060 --> 00:03:24,780 txt. 63 00:03:25,290 --> 00:03:29,910 So what this is saying is touch inside a random folder. 64 00:03:31,140 --> 00:03:33,480 It can be folder 1 to 500. 65 00:03:33,480 --> 00:03:37,050 Any random number in there file called needle dot txt. 66 00:03:37,260 --> 00:03:41,850 So we've created a file called needle that txt in somewhere in the haystack. 67 00:03:41,850 --> 00:03:43,590 But we don't know where. 68 00:03:43,590 --> 00:03:47,280 And it's our job now to use the find command in order to find it. 69 00:03:47,850 --> 00:03:50,280 So how can we find the needle? 70 00:03:50,820 --> 00:03:51,720 Let's have a thing through this. 71 00:03:51,720 --> 00:03:53,520 Clear the screen and maximize it. 72 00:03:53,520 --> 00:03:56,340 So let's just take a look how we might do this. 73 00:03:56,340 --> 00:04:00,480 So first of all, we're going to use the find command and we're going to start. 74 00:04:00,480 --> 00:04:01,340 Where are we going to start? 75 00:04:01,350 --> 00:04:03,330 We probably start with the haystack folder. 76 00:04:03,330 --> 00:04:03,500 Okay. 77 00:04:03,600 --> 00:04:04,740 We know it's in the haystack. 78 00:04:04,740 --> 00:04:07,140 So we're going to start searching from that point. 79 00:04:07,230 --> 00:04:09,180 And we know that it's a file, right? 80 00:04:09,180 --> 00:04:13,110 So we don't need to look at all the directories, but remembering that the find command will by default 81 00:04:13,110 --> 00:04:14,850 list out files and directories. 82 00:04:14,850 --> 00:04:18,750 So we're going to worry about searching through all the searching and returning folders. 83 00:04:18,750 --> 00:04:27,750 Let's just look for files and we know that its name is needle dot txt don't we. 84 00:04:29,820 --> 00:04:30,390 Okay. 85 00:04:30,420 --> 00:04:33,990 So if we do that and press enter, let's see if it works. 86 00:04:34,440 --> 00:04:35,160 And it has. 87 00:04:35,460 --> 00:04:39,960 It's found needle dot txt inside folder 449. 88 00:04:39,960 --> 00:04:40,980 So how awesome is that? 89 00:04:40,980 --> 00:04:41,160 Right. 90 00:04:41,160 --> 00:04:48,090 We've managed to find the needle in the haystack, but now let's try and move it to our desktop. 91 00:04:48,090 --> 00:04:48,470 Okay. 92 00:04:48,570 --> 00:04:55,320 So to do that, now that we've got the result, we will use the exec option to execute something on 93 00:04:55,320 --> 00:04:55,560 it. 94 00:04:55,560 --> 00:04:57,210 Now to move something. 95 00:04:57,210 --> 00:05:01,920 Remember, you would type move then what you want to move and where you want to move it to. 96 00:05:01,920 --> 00:05:05,010 And remember, of course, we've got to end everything with a backslash semicolon. 97 00:05:05,010 --> 00:05:05,170 Okay? 98 00:05:05,190 --> 00:05:07,740 This is how you end the exit option. 99 00:05:07,740 --> 00:05:11,190 So we are we're going to move something to somewhere. 100 00:05:11,190 --> 00:05:12,810 Now we want to move it onto our desktop. 101 00:05:12,810 --> 00:05:15,390 So let's just put a tilde slash desktop. 102 00:05:15,420 --> 00:05:15,740 Okay? 103 00:05:15,810 --> 00:05:18,120 So that is our desktop. 104 00:05:18,120 --> 00:05:19,050 That's where we're going to move it. 105 00:05:19,050 --> 00:05:20,130 And what are we going to move? 106 00:05:20,130 --> 00:05:24,750 Well, that file so we just put a square, a set of squiggly brackets and it works the same for one 107 00:05:24,750 --> 00:05:27,300 file as it would for 100,000. 108 00:05:27,300 --> 00:05:28,620 So fingers crossed. 109 00:05:28,620 --> 00:05:30,600 If we go ahead and do that, we press enter. 110 00:05:30,990 --> 00:05:36,780 And now if I just close the terminal and have a look on our desktop, we've actually done it. 111 00:05:36,780 --> 00:05:43,290 We've managed to move needle dot text all the way from somewhere inside that haystack of potentially 112 00:05:43,290 --> 00:05:44,490 50,000 files. 113 00:05:44,490 --> 00:05:49,170 Find it and move it to our to move it to our desktop. 114 00:05:49,170 --> 00:05:54,000 So that's just how awesome what you've learned in the past few videos can be. 115 00:05:54,810 --> 00:06:00,540 So what you've seen in the past few videos is that the fine command is a total beast of a command. 116 00:06:00,900 --> 00:06:04,020 You've seen it do so many, so very many things with it. 117 00:06:04,290 --> 00:06:07,020 But the main key point I'm just going to go through in a quick summary. 118 00:06:07,260 --> 00:06:11,880 So the fine command can be used to execute sophisticated search tasks. 119 00:06:11,910 --> 00:06:16,290 You've also seen that you've seen how to use the locate command, and that's very good for just quick, 120 00:06:16,830 --> 00:06:18,360 quick like searches. 121 00:06:18,360 --> 00:06:22,260 But if you want to do something very sophisticated, the find command is what you're going to want to 122 00:06:22,260 --> 00:06:22,800 use. 123 00:06:23,640 --> 00:06:27,630 First of all, it doesn't use a database, whereas the locate command does the find command works directly 124 00:06:27,630 --> 00:06:32,130 on your file system, which means that it's always going to be correct, but it might be slightly slower. 125 00:06:32,130 --> 00:06:33,660 So that's just something to bear in mind. 126 00:06:33,840 --> 00:06:38,520 And the fine command allows you to build up search queries where you can search by the name of the file, 127 00:06:38,520 --> 00:06:42,640 the type of the thing that you're searching for, the size and so much more. 128 00:06:42,660 --> 00:06:42,870 Okay. 129 00:06:42,890 --> 00:06:48,960 You can see examples of those in the man page, just type man, then find and you'll be able to read 130 00:06:48,960 --> 00:06:50,340 the manual page for the fine command. 131 00:06:50,520 --> 00:06:52,030 There's just so much that it can do. 132 00:06:52,050 --> 00:06:52,510 Okay. 133 00:06:53,370 --> 00:06:59,520 And once you've got this big list of results, you can use the exec option to execute another command 134 00:06:59,520 --> 00:07:01,040 on each of those results. 135 00:07:01,050 --> 00:07:04,580 Just remember to end that with the backslash, then a semicolon. 136 00:07:04,590 --> 00:07:08,850 And if you're working with a small number of files and you're doing something potentially destructive 137 00:07:08,850 --> 00:07:17,010 like deleting or removing or something like that or moving files, then, you know, use the OC option 138 00:07:17,010 --> 00:07:21,690 instead because then it will prompt you to say, is this one okay or is this okay? 139 00:07:21,690 --> 00:07:22,400 Or Is this okay? 140 00:07:22,410 --> 00:07:24,030 And you've got to authorize it every time. 141 00:07:24,060 --> 00:07:26,590 I guess that's something to to bear in mind as well. 142 00:07:26,610 --> 00:07:31,920 Now, after what you've learned in the from the last few days about the fine command, everything else 143 00:07:31,920 --> 00:07:35,290 that you're going to learn in the next few videos is going to seem really like a breeze. 144 00:07:35,360 --> 00:07:35,550 Okay. 145 00:07:35,550 --> 00:07:40,860 So in the next video, I'm going to be showing you how to open files on the command line and read what's 146 00:07:40,860 --> 00:07:41,690 inside them. 147 00:07:41,700 --> 00:07:44,400 And I'll also be making plenty of kitten jokes. 148 00:07:44,670 --> 00:07:47,850 So for all that good stuff, I'll see you in the next video.