1 00:00:00,180 --> 00:00:01,710 Hello, you beautiful people. 2 00:00:01,710 --> 00:00:06,689 And welcome back where we're going to be continuing our discussion of the find command and how we can 3 00:00:06,689 --> 00:00:10,530 control the search depth that the find command searches to. 4 00:00:10,560 --> 00:00:15,780 So if I open up our file explorer, I've made a few, few new folders. 5 00:00:15,780 --> 00:00:20,370 So in our documents folder I have made a folder called Level two. 6 00:00:20,370 --> 00:00:25,170 And inside there I've got a file called two dot txt and then a folder called level three. 7 00:00:25,170 --> 00:00:31,280 And inside there I've got a file called three dot tfsi then level 44. txt, level five and five point 8 00:00:31,320 --> 00:00:32,490 txt where it ends. 9 00:00:32,729 --> 00:00:37,710 And we're going to be using this to take a look at how we can control the search depth that the find 10 00:00:37,710 --> 00:00:39,510 command searches to. 11 00:00:39,510 --> 00:00:43,290 So all of that stuff is in our documents folder, as you can see here. 12 00:00:43,290 --> 00:00:48,180 So I'm just going to change into our documents folder and use an LS and you can see that level two is 13 00:00:48,180 --> 00:00:48,480 in there. 14 00:00:48,480 --> 00:00:52,500 So this is what we're seeing at the minute, this is what we are currently in. 15 00:00:52,740 --> 00:00:54,900 So let's clear the screen and start our discussion. 16 00:00:55,080 --> 00:01:00,420 If I just run the find command from here, the find command will search to an infinite depth. 17 00:01:00,420 --> 00:01:05,430 It will list every file and every folder from this point in the file system. 18 00:01:05,430 --> 00:01:07,230 Okay, so from here and downwards. 19 00:01:07,230 --> 00:01:14,370 So if I run that, you'll see it shows us level two and it will show us everything inside there. 20 00:01:14,370 --> 00:01:20,790 So you'll see we get to dot txt and it shows us a level 33. txt, level four, 4.2 SDA level five and 21 00:01:20,790 --> 00:01:21,630 five SDA. 22 00:01:21,630 --> 00:01:27,660 Everything is shown in there, but we can control the depth that the fine command searches to by using 23 00:01:27,660 --> 00:01:29,490 the max depth option. 24 00:01:29,490 --> 00:01:30,990 So let me show you how we do that. 25 00:01:30,990 --> 00:01:36,210 So if we type find we're going to again start from our current working directory, we can actually specify 26 00:01:36,210 --> 00:01:38,940 that to make it a bit clearer by using the dot. 27 00:01:38,940 --> 00:01:43,440 By the way, remember dot means this directory, so I'm actually going to use this from now on. 28 00:01:43,440 --> 00:01:48,180 I'm just going to always start by saying, okay, start from this directory by using the dot. 29 00:01:48,660 --> 00:01:55,290 So the max depth option, you type one dash and then max depth and you can specify the depth here. 30 00:01:55,290 --> 00:01:56,610 So let's say we put one. 31 00:01:56,610 --> 00:01:59,790 So the first thing you might know is, is Ziad, why is there just one dash? 32 00:01:59,790 --> 00:02:02,820 I thought you said for long form options you need to have two dashes. 33 00:02:02,820 --> 00:02:03,690 Well, that's right. 34 00:02:03,690 --> 00:02:08,610 But for the find command, you only have one dash for these options because there's so many of them. 35 00:02:08,610 --> 00:02:11,039 There's so many long form options. 36 00:02:11,039 --> 00:02:15,120 I guess they tried to save you typing by just reducing it to one dash. 37 00:02:15,150 --> 00:02:16,560 Okay, so here we are. 38 00:02:16,560 --> 00:02:20,070 We have just one dash max depth and then one. 39 00:02:20,070 --> 00:02:23,010 And this is saying only search to a maximum depth of one. 40 00:02:23,010 --> 00:02:23,340 Really. 41 00:02:23,340 --> 00:02:24,930 So if we see that, let's see what happens. 42 00:02:24,930 --> 00:02:27,690 You see here that we only see the level two folder. 43 00:02:27,690 --> 00:02:33,150 So a max depth of one is just like seeing what you see here. 44 00:02:33,150 --> 00:02:37,230 It only shows you what is in the current directory. 45 00:02:37,260 --> 00:02:44,190 Okay, now if I do max depth of two, that's like showing you what's here and what's one level down. 46 00:02:44,190 --> 00:02:44,560 Okay. 47 00:02:44,700 --> 00:02:49,620 So if we if we take a look here, what we should see is we should see level two and then it will go 48 00:02:49,620 --> 00:02:53,160 inside and it will show you to TXT and the level three folder. 49 00:02:53,430 --> 00:02:58,470 So if we run that max depth of two, we see level two, which is here, it's showing us the level two 50 00:02:58,470 --> 00:02:58,860 folder. 51 00:02:58,860 --> 00:02:59,670 This is where we start. 52 00:02:59,670 --> 00:03:04,410 So it's showing us the level two folder going in there, showing us to dot txt and level three. 53 00:03:04,410 --> 00:03:07,890 So we see the level two folder two point txt and level three. 54 00:03:07,920 --> 00:03:08,190 Okay. 55 00:03:08,310 --> 00:03:13,950 Now if we want to go to a max depth of three, that's going to go down another level into level three. 56 00:03:14,220 --> 00:03:21,150 So if I run that, we'll see now that we see three dot txt and level the level four folder shown as 57 00:03:21,150 --> 00:03:21,450 well. 58 00:03:21,450 --> 00:03:26,850 If we keep going deeper, if we do max up the four, we're now starting to take a look inside level 59 00:03:26,850 --> 00:03:27,180 four. 60 00:03:27,180 --> 00:03:33,540 We're seeing four dot txt and the level five folder and if we do max depth of five, it's going to go 61 00:03:33,540 --> 00:03:39,690 down even further all the way until we see five txt and you can give it like you know, a max depth 62 00:03:39,690 --> 00:03:44,250 of 100 and it will still work because all you're defining is a maximum depth. 63 00:03:44,250 --> 00:03:44,740 Okay? 64 00:03:44,820 --> 00:03:47,010 It doesn't mean it will go all that way. 65 00:03:47,010 --> 00:03:50,190 That's just as far as it could go if it was possible. 66 00:03:50,640 --> 00:03:55,200 Now by default there is no maximum depth, so it will list everything here. 67 00:03:55,200 --> 00:04:00,330 We didn't have to specify a maximum depth if you wanted to go all the way into the file tree. 68 00:04:00,330 --> 00:04:04,890 But if you want to limit how far it goes, that's when you use the max depth option and you say, Hey, 69 00:04:04,890 --> 00:04:07,380 I only want you to show me what's in this folder. 70 00:04:07,380 --> 00:04:13,260 That's when you use max depth of one, and it's incredibly useful for listing out what's in the current 71 00:04:13,260 --> 00:04:13,950 folder. 72 00:04:14,220 --> 00:04:19,170 Now, if we just clear the screen, there's another really great option that the fine command has, 73 00:04:19,170 --> 00:04:20,790 which is the type option. 74 00:04:20,790 --> 00:04:26,670 So if we just go all the way back up to our documents here, the type option allows you to search for 75 00:04:26,670 --> 00:04:29,220 just files or just directories. 76 00:04:29,220 --> 00:04:32,010 Notice by default the find command lists both. 77 00:04:32,010 --> 00:04:37,050 It lists both files and directories, but the type option lets you specify just one. 78 00:04:37,050 --> 00:04:42,570 So if I start here in our documents folder and I list out everything starting at this folder, you see 79 00:04:42,570 --> 00:04:46,140 that we list out the folders and their files. 80 00:04:46,140 --> 00:04:52,920 But if I said, okay, I just want to list out the files, what I do is type the type option with again 81 00:04:52,920 --> 00:04:58,080 noticing just one dash and if I just want files, I would type f f for file. 82 00:04:58,110 --> 00:04:58,500 Okay. 83 00:04:58,530 --> 00:04:59,880 So if I press enter now. 84 00:05:00,230 --> 00:05:06,650 Now you'll see that we just get 4.5.23.2 HD and 2.2 HD. 85 00:05:06,680 --> 00:05:08,510 We just get the files. 86 00:05:08,540 --> 00:05:09,080 Likewise. 87 00:05:09,080 --> 00:05:13,490 I could just get the folders by pressing instead of having f have dx. 88 00:05:13,790 --> 00:05:16,640 So if I type dx, you know, we now just get the folders. 89 00:05:16,640 --> 00:05:22,010 So level two folder, the level three folder, the level four folder and the level five folder. 90 00:05:22,370 --> 00:05:30,710 Starting at this directory here and you can combine this of course with the max depth option. 91 00:05:31,100 --> 00:05:39,620 So if I do max depth of one now all we're doing is we're going to a maximum depth of one and just showing 92 00:05:39,620 --> 00:05:40,100 the folders. 93 00:05:40,100 --> 00:05:44,900 Now I did this on purpose to show you that if you put them this way around, you'll get a warning and 94 00:05:44,900 --> 00:05:46,100 it says warning. 95 00:05:46,100 --> 00:05:53,080 You have specified the max depth option after a non option argument type, but options are not positional. 96 00:05:53,360 --> 00:05:55,640 I'll tell you what this means shortly. 97 00:05:55,820 --> 00:05:56,390 Really quickly. 98 00:05:56,390 --> 00:05:56,590 Okay. 99 00:05:56,600 --> 00:05:59,540 What this means is just put max depth first. 100 00:06:00,800 --> 00:06:02,150 So that's all you've got to do. 101 00:06:02,150 --> 00:06:02,330 Okay. 102 00:06:02,340 --> 00:06:03,260 And that warning goes away. 103 00:06:03,260 --> 00:06:06,180 So if you're going to specify multiple options, just put the max depth first. 104 00:06:06,200 --> 00:06:09,740 If I if I clear the screen, you'll see that warning goes away. 105 00:06:10,190 --> 00:06:14,050 So now we're searching to a maximum depth of one and showing all the directories. 106 00:06:14,060 --> 00:06:15,560 Let's go to a maximum depth of two. 107 00:06:16,010 --> 00:06:17,760 We're now seeing the level three folder. 108 00:06:17,780 --> 00:06:25,070 If I go to a maximum depth of four, let's say oops, not 42, max depth of four as do three. 109 00:06:25,190 --> 00:06:26,240 Can't type today. 110 00:06:26,270 --> 00:06:27,070 Maximum depth three. 111 00:06:27,080 --> 00:06:29,660 We're going to level three and we're seeing the level four folder. 112 00:06:29,660 --> 00:06:32,780 And if we go into the level four folder, we'll see the level five folder. 113 00:06:32,780 --> 00:06:38,030 And if we go into the level five, go to level five, it won't make any difference because all that's 114 00:06:38,030 --> 00:06:44,630 in level five is another file which isn't being shown because all we're looking for is directories. 115 00:06:45,020 --> 00:06:51,110 So if I go and change that to an F now, you'll see we list all the files and you know, it works exactly 116 00:06:51,110 --> 00:06:51,470 the same. 117 00:06:51,470 --> 00:06:56,780 So these are really good options to combine together and there's loads of things that you can do to 118 00:06:56,780 --> 00:07:00,410 customize the way that the find command actually searches. 119 00:07:00,410 --> 00:07:06,470 But just to quickly summarize that the type option has two possible inputs. 120 00:07:06,470 --> 00:07:11,270 You could give it F for file or D for directory. 121 00:07:11,270 --> 00:07:16,310 And if you're going to use it with the find command, make sure that you give it the max depth option 122 00:07:16,310 --> 00:07:17,300 first. 123 00:07:17,570 --> 00:07:20,840 And if we're going to specify where to start from, make sure that comes as well. 124 00:07:20,840 --> 00:07:25,820 So if we're going to do in the C folder and we're going to list every single file in the Z folder, 125 00:07:25,820 --> 00:07:28,670 let's say, but only to a maximum depth of one. 126 00:07:29,510 --> 00:07:30,290 There you are. 127 00:07:30,320 --> 00:07:33,110 This is every single file that is in the Z folder. 128 00:07:33,140 --> 00:07:33,580 Oops. 129 00:07:33,710 --> 00:07:34,850 Let me just clear the screen and do that. 130 00:07:34,850 --> 00:07:38,450 This is every single file in the C folder without any directories. 131 00:07:38,450 --> 00:07:42,820 And if we just want to see the directories, then here they are. 132 00:07:42,830 --> 00:07:49,820 So that's a very useful combination of commands to have there and it will come very useful in your assignment. 133 00:07:49,820 --> 00:07:52,880 So I'm going to break this video here, keep it nice and short and sweet. 134 00:07:52,880 --> 00:07:56,150 And in the next video, we're going to pick up with some more awesome stuff you can do with the fine 135 00:07:56,150 --> 00:07:56,720 command.