1 00:00:00,270 --> 00:00:01,650 Hello, very beautiful people. 2 00:00:01,650 --> 00:00:02,460 And welcome back. 3 00:00:02,460 --> 00:00:07,740 We're going to be continuing on our discussion of the find command in this video by starting off showing 4 00:00:07,740 --> 00:00:10,650 you how to search for things by name. 5 00:00:10,650 --> 00:00:17,070 So let's say we want to find this file here called Five-test and we're back in our home folder. 6 00:00:17,310 --> 00:00:20,070 We're not in our documents folder anymore, we're just in our home folder. 7 00:00:20,070 --> 00:00:25,140 And we know that this five-test is somewhere in our home directory. 8 00:00:25,140 --> 00:00:29,730 It's somewhere below this point in the file system, but we're not exactly sure where and we're going 9 00:00:29,730 --> 00:00:31,980 to use the find command to find it for us. 10 00:00:32,340 --> 00:00:35,520 So if we clear the screen, let's say, okay, we're going to find command. 11 00:00:35,520 --> 00:00:39,720 We're going to start from this point in the file system, by the way, this is just a matter of personal 12 00:00:39,720 --> 00:00:40,260 preference. 13 00:00:40,260 --> 00:00:44,400 Actually having the dot, you don't need it, but I'd like to put it there just to make it a bit more 14 00:00:44,400 --> 00:00:44,950 complete. 15 00:00:44,970 --> 00:00:45,250 Okay. 16 00:00:45,360 --> 00:00:49,560 So there we are find we're starting at this position in the file directory and we want to search by 17 00:00:49,560 --> 00:00:50,040 name. 18 00:00:50,040 --> 00:00:55,320 So we give it the name option again just with one dash and then in speech marks. 19 00:00:55,320 --> 00:00:57,470 So in double quotes, we want to search. 20 00:00:57,580 --> 00:01:00,060 We're going to put the pattern that we're searching for. 21 00:01:00,060 --> 00:01:06,210 We're going to put five txt and it does need to be in quotes, otherwise the find command plays up some 22 00:01:06,210 --> 00:01:06,420 time. 23 00:01:06,420 --> 00:01:12,540 So make sure you just put it in speech marks in these double quotes and you know that that will be that 24 00:01:12,540 --> 00:01:13,290 would be much better. 25 00:01:13,680 --> 00:01:19,830 So if we do if we do that and press enter, we see that the fine command has indeed found for the five 26 00:01:19,830 --> 00:01:26,760 dot txt and it's given us the path all the way to it starting at the current working directory. 27 00:01:27,000 --> 00:01:29,100 So what if we wanted to find three dot txt? 28 00:01:29,520 --> 00:01:31,200 That will work as well. 29 00:01:31,470 --> 00:01:33,510 So it's found a path to three dot txt. 30 00:01:33,540 --> 00:01:35,970 You can build regular expressions in here. 31 00:01:35,970 --> 00:01:43,200 So if I put a star it will find every dot txt file from this point in the file system. 32 00:01:43,200 --> 00:01:47,760 So we see we've got one in music, we've got find me 4.2 which I'd forgotten created earlier in the, 33 00:01:47,760 --> 00:01:50,070 in the, in the course. 34 00:01:50,070 --> 00:01:54,480 We've got some in some hidden folders, we have them all over the place. 35 00:01:54,480 --> 00:01:57,630 We can actually also limit the depth that we search to. 36 00:01:57,630 --> 00:02:01,890 So if we go to a maximum depth of, let's say two, remembering that we're going to put the max depth 37 00:02:01,890 --> 00:02:06,210 option as the first option, otherwise we get a big warning, don't we? 38 00:02:06,210 --> 00:02:12,240 So if I do max depth to name any name that ends in txt, we can see that we found all the files at ending 39 00:02:12,240 --> 00:02:15,180 not txt but only going to depths in. 40 00:02:15,180 --> 00:02:16,560 So that's really, really cool, right? 41 00:02:16,560 --> 00:02:22,290 You can search by name like that and you can also have you can also have wildcards. 42 00:02:22,290 --> 00:02:26,970 So I could do file and then a number txt and nothing comes up. 43 00:02:26,970 --> 00:02:27,750 What if I did? 44 00:02:28,980 --> 00:02:33,600 What if I did something like question marked txt nothing comes up. 45 00:02:33,600 --> 00:02:40,850 But if I go to a big depth of like let's say ten now we see that we just get 4.5.3. txt and two point 46 00:02:40,870 --> 00:02:47,610 txt, but these find me one find me to find me four etc. are ignored because they don't match this world, 47 00:02:47,670 --> 00:02:48,990 this regular expression. 48 00:02:48,990 --> 00:02:51,630 So that is a really powerful ability. 49 00:02:51,630 --> 00:02:58,140 Just by building upon your knowledge of regular expressions and wildcards, you can really tailor the 50 00:02:58,140 --> 00:02:59,940 fine command to your needs. 51 00:02:59,940 --> 00:03:06,060 And the one thing I should note here is that you can't do Bray's expansion inside inside the name Commander. 52 00:03:06,330 --> 00:03:07,650 So that's just something to bear in mind. 53 00:03:07,920 --> 00:03:08,410 Okay? 54 00:03:08,910 --> 00:03:10,650 At least, at least inside double quotes. 55 00:03:10,650 --> 00:03:11,880 Let's just leave that there. 56 00:03:12,720 --> 00:03:13,170 Okay. 57 00:03:13,170 --> 00:03:19,590 So the the other thing is that you can search in a case insensitive way by searching dot in name. 58 00:03:19,590 --> 00:03:23,700 So if I change this here to txt all in uppercase, let me clear the screen. 59 00:03:24,090 --> 00:03:28,380 TXT in uppercase that will now match. 60 00:03:28,380 --> 00:03:28,620 Okay. 61 00:03:28,620 --> 00:03:29,760 I probably did that wrong way around. 62 00:03:29,760 --> 00:03:31,800 If I do it like this, just search name. 63 00:03:31,800 --> 00:03:32,370 Okay. 64 00:03:32,490 --> 00:03:38,160 Now you'll see nothing matches because now it's searching case sensitive but if I change it to I name 65 00:03:38,160 --> 00:03:44,700 so it's case insensitive searching for the name so uppercase and lowercase don't matter now it will 66 00:03:44,700 --> 00:03:49,020 match because it doesn't care that this text is in uppercase. 67 00:03:49,020 --> 00:03:49,470 So that's good. 68 00:03:49,470 --> 00:03:53,430 If you're not sure whether you put an uppercase in the file name, it's good to search with IE name 69 00:03:53,430 --> 00:03:56,370 to make the search just a bit more general. 70 00:03:56,640 --> 00:04:02,340 Now another interesting way to search for files with the find command is by file size. 71 00:04:02,340 --> 00:04:09,000 So let's say that we wanted to search the entire file system for every file that is larger than 100 72 00:04:09,000 --> 00:04:09,810 kilobytes. 73 00:04:09,990 --> 00:04:11,040 So let's clear the screen. 74 00:04:11,190 --> 00:04:12,360 How would we do that? 75 00:04:12,360 --> 00:04:14,850 Well, what we do is we type the find command. 76 00:04:15,000 --> 00:04:18,870 Then we need to give it, of course, a place to start searching from. 77 00:04:18,870 --> 00:04:23,850 So let's start from the very base of the file system, because we want to find every file on the system. 78 00:04:23,850 --> 00:04:25,620 So let's start at the very base of the system. 79 00:04:25,800 --> 00:04:30,000 We want to search for files that are larger than 100 kilobytes. 80 00:04:30,000 --> 00:04:31,860 So let's say that we want files. 81 00:04:31,860 --> 00:04:36,840 So let's specify a type of F, so because we're just looking for files, not folders, and we want a 82 00:04:36,840 --> 00:04:37,380 size. 83 00:04:37,380 --> 00:04:38,850 So we're going to give it the size option. 84 00:04:38,850 --> 00:04:40,050 Again, one dash. 85 00:04:40,050 --> 00:04:44,010 And now this is how you'd say greater than 100 kilobytes. 86 00:04:44,220 --> 00:04:47,820 So you see the plus meaning greater if it was less than you'd have minus. 87 00:04:47,820 --> 00:04:49,740 So that's less than 100 kilobytes. 88 00:04:49,740 --> 00:04:55,410 But we want more than so more than 100 then a lowercase k for kilobytes. 89 00:04:55,410 --> 00:04:59,580 So if I press enter you'll see that we get a whole bunch of. 90 00:05:00,190 --> 00:05:05,560 As we look for all the files that are bigger than 100 kilobytes starting at the very base of our file 91 00:05:05,560 --> 00:05:06,060 system. 92 00:05:06,070 --> 00:05:11,140 But one thing you might have noticed and if you had a quick I if I scroll up to the top is that we got 93 00:05:11,140 --> 00:05:13,780 a lot of permission denied errors. 94 00:05:14,080 --> 00:05:16,600 If I can show you by scrolling all the way back up. 95 00:05:16,600 --> 00:05:17,080 There we go. 96 00:05:17,110 --> 00:05:20,410 You can see that we've got a lot of permission denied, permission denied, permission denied. 97 00:05:20,410 --> 00:05:23,890 And the reason is that's because we started at the base of our file system. 98 00:05:23,890 --> 00:05:28,960 And remember, the find command will try to enter every folder, but it couldn't because it didn't have 99 00:05:28,960 --> 00:05:33,670 the required privileges to enter some of the folders in our base directory that are only accessible 100 00:05:33,670 --> 00:05:36,580 to the root user, to the super user, to the administrator. 101 00:05:36,580 --> 00:05:36,970 Okay. 102 00:05:37,000 --> 00:05:41,920 So to fix that, we just prefix the command with the sudo command. 103 00:05:41,920 --> 00:05:46,840 So we're going to go sudo and then do the rest of it and we'll get a whole lot less errors because we're 104 00:05:46,840 --> 00:05:50,050 not going to have those access errors before now. 105 00:05:50,050 --> 00:05:56,080 We can count the amount of results that we actually got out of this by piping the entire thing into 106 00:05:56,080 --> 00:05:58,120 the word command with the WL option. 107 00:05:58,120 --> 00:06:02,770 And what this will do is it will count the amount of lines in the output that you give it. 108 00:06:02,770 --> 00:06:06,550 So if you notice when we run this, we get one result per line. 109 00:06:06,970 --> 00:06:11,350 So if we pipe all of that into the word command and give it the WL option, this will count how many 110 00:06:11,350 --> 00:06:11,950 lines there are. 111 00:06:11,950 --> 00:06:18,790 And if we do that, we get 3144 results, which is a whole bunch of results. 112 00:06:19,030 --> 00:06:23,380 Now, one thing that's interesting is the way that you can chain together different sizes. 113 00:06:23,380 --> 00:06:27,670 So here we're saying it needs to be greater than 100 kilobytes, and this is how we'd say it has to 114 00:06:27,670 --> 00:06:29,800 be less than five megabytes. 115 00:06:30,190 --> 00:06:34,300 So here what we're doing is we're chaining together all these different requirements. 116 00:06:34,300 --> 00:06:42,190 We're saying it has to be a file and the file size has to be bigger than 100 kilobytes, and the file 117 00:06:42,190 --> 00:06:44,590 size has to be less than five megabytes. 118 00:06:44,590 --> 00:06:49,030 And if we count how many of them there are, we see that we get a quite a few less. 119 00:06:49,030 --> 00:06:54,190 Now we're going to get 3030 files instead of 3144. 120 00:06:54,190 --> 00:07:02,470 So there's about 114 files that aren't being shown anymore because they they were bigger than five megabytes. 121 00:07:02,470 --> 00:07:08,260 So if I click the screen, one thing that I really want to highlight here is the way that we're chaining 122 00:07:08,290 --> 00:07:09,940 together different requirements. 123 00:07:09,940 --> 00:07:10,220 Okay. 124 00:07:10,300 --> 00:07:18,550 So here we're saying it has to be a file and the size has to be greater than 100 kilobytes and the size 125 00:07:18,550 --> 00:07:24,580 has to be less than five megabytes in order for it to be contained in our requirement. 126 00:07:24,580 --> 00:07:24,880 Okay. 127 00:07:25,000 --> 00:07:31,810 So how would we say something like, okay, I want to find all the files that are less than 100 kilobytes 128 00:07:31,840 --> 00:07:34,540 or bigger than five megabytes. 129 00:07:34,620 --> 00:07:40,090 Okay, well, the way that we do that, I mean, first of all, if we wanted to say less than 100 kilobytes, 130 00:07:40,090 --> 00:07:40,600 we'd do that. 131 00:07:40,600 --> 00:07:43,900 And if wouldn't say greater than five megabytes, we need to change that to a plus. 132 00:07:43,900 --> 00:07:47,770 But at the minute here, let's see how many results we get. 133 00:07:48,040 --> 00:07:54,460 We're going to get zero results because it's impossible for a file to be less than 100 kilobytes and 134 00:07:54,460 --> 00:07:56,020 greater than five megabytes. 135 00:07:56,230 --> 00:08:00,100 You can't be bigger than five megabytes at the same time that you're less than 100 kilobytes. 136 00:08:00,100 --> 00:08:01,030 That's not possible. 137 00:08:01,030 --> 00:08:07,060 What we want to say is it needs to be less than 100 kilobytes or greater than five megabytes not. 138 00:08:07,060 --> 00:08:11,740 And it needs to be less than a hundred gigabytes or greater than 100 greater than five megabytes. 139 00:08:11,740 --> 00:08:17,770 The way that you do that is you type a-0 in between the two requirements. 140 00:08:17,770 --> 00:08:23,440 So here what we're saying is it's got to be a file and its size needs to be less than 100 kilobytes 141 00:08:23,440 --> 00:08:24,880 or greater than five. 142 00:08:24,880 --> 00:08:32,950 So if we do that, you can see now that we get a whole bunch of results, 199,112 results. 143 00:08:33,250 --> 00:08:38,409 Now, you can go quite wild with this, this ending and ignoring, but I think that will do what I think 144 00:08:38,409 --> 00:08:39,370 that will do for now. 145 00:08:39,370 --> 00:08:44,770 You can also do not and loads of other different logical operations and if you're familiar with Boolean 146 00:08:44,770 --> 00:08:50,170 logic, but I'll leave that up to you if you want to find more by looking at the man pages, it would 147 00:08:50,170 --> 00:08:52,090 just be a bit of a mess to show by video. 148 00:08:52,210 --> 00:08:54,010 So we've covered quite a lot in this video. 149 00:08:54,010 --> 00:09:01,270 We've seen how to use the name option for the fine command to search for things by name, so you'd use 150 00:09:01,270 --> 00:09:07,030 dash name and then give it in double quotes, a certain regular expression that you wanted file names 151 00:09:07,030 --> 00:09:12,670 to match so I could do anything ending in dot txt for example, using the star wild card and that would 152 00:09:12,670 --> 00:09:16,000 give us all the files that ended in txt. 153 00:09:16,000 --> 00:09:23,230 And you can make the search case insensitive so that uppercase and lowercase don't matter by using the 154 00:09:23,620 --> 00:09:25,630 by using the the enum option. 155 00:09:25,630 --> 00:09:31,540 So now even though we have said dot text in uppercase, it doesn't matter because we're using the name 156 00:09:31,540 --> 00:09:31,960 option. 157 00:09:31,960 --> 00:09:35,410 So that's the first thing we looked at how to find files by name. 158 00:09:35,410 --> 00:09:41,620 Then we took a look at how you could find files by their file size and you saw that you use the size 159 00:09:41,620 --> 00:09:48,880 option and then you give it a certain file size and the plus means above, the minus means below. 160 00:09:49,090 --> 00:09:50,830 Or you could actually give it just exactly. 161 00:09:50,830 --> 00:09:52,300 For example, 500 megabytes. 162 00:09:52,300 --> 00:09:53,980 That's exactly 500 megabytes. 163 00:09:53,980 --> 00:09:55,540 This is above 500 megabytes. 164 00:09:55,540 --> 00:09:57,250 This is below 500 megabytes. 165 00:09:57,280 --> 00:09:59,530 A capital G, by the way, is gigabyte. 166 00:10:00,260 --> 00:10:04,420 And you can find more on that in the man page for the find command. 167 00:10:04,430 --> 00:10:08,210 But in the next video, what we're going to be doing is we're going to be jumping on to some very exciting 168 00:10:08,210 --> 00:10:08,540 stuff. 169 00:10:08,540 --> 00:10:12,890 And what we're going to be showing you is how you can use the find command to not only give you a whole 170 00:10:12,890 --> 00:10:19,070 bunch of results, but in the same command also execute another command or even another pipeline on 171 00:10:19,070 --> 00:10:21,360 every single one of those results. 172 00:10:21,360 --> 00:10:27,080 So this is a this is a turbocharger for your work on the Linux command line, and I hope you're very, 173 00:10:27,080 --> 00:10:27,710 very excited. 174 00:10:27,710 --> 00:10:32,360 So let's cut the video here and jump over into the next one where we're going to learn how to gain even 175 00:10:32,360 --> 00:10:33,680 more superpowers.