1 00:00:06,719 --> 00:00:11,970 Find this so powerful. I wanted to share some more advanced find examples with you. 2 00:00:12,589 --> 00:00:13,900 So let me show you. 3 00:00:15,250 --> 00:00:19,859 To start with sudo find minus type F, which 4 00:00:19,859 --> 00:00:24,469 is looking for files minus size plus 100m. 5 00:00:27,350 --> 00:00:30,100 That's for files only that have a size bigger than 100 megabyte. 6 00:00:31,929 --> 00:00:38,554 Then I'm using find etc exec grab 7 00:00:38,554 --> 00:00:45,179 l student curly braces, backslash semicolon. 8 00:00:45,899 --> 00:00:51,469 Now what is that? Well, this is something that you could do in another way as well, but it 9 00:00:51,469 --> 00:00:57,039 is finding files in the etc directory and on these files it will run the command grep l student, 10 00:00:57,039 --> 00:01:02,609 which means that it is going to find files that have the text student within the file. 11 00:01:05,150 --> 00:01:11,830 Now we have one minus exec statement here. I'm going to open a second exec statement 12 00:01:11,830 --> 00:01:18,510 and that is sudo CP curly braces. We are going to copy it to find contents. 13 00:01:20,489 --> 00:01:27,340 And this time I don't want to see any error messages. And that's why I'm putting a togreat then dev null behind it. 14 00:01:28,299 --> 00:01:33,439 Toogreat then dev null will suppress any error messages. And that goes for 15 00:01:33,439 --> 00:01:38,579 a clean output. Very useful if you're expecting a lot of error messages. 16 00:01:39,560 --> 00:01:43,920 One little problem. The directory find contents does not exist. So I'm going to use 17 00:01:43,920 --> 00:01:48,280 control A again to move my cursor to the start of the command line. 18 00:01:48,780 --> 00:01:54,534 And I'm using mkdir find mkdir p find contents to 19 00:01:54,534 --> 00:02:00,289 create this directory before we run the actual find command. 20 00:02:01,510 --> 00:02:08,245 And oh boy, what do we see here? We see a missing argument to exec. 21 00:02:08,245 --> 00:02:14,979 Does that make sense? Yes, because every exec needs to be closed with a semicolon. 22 00:02:15,580 --> 00:02:22,476 So let me put the semicolon to close the exec that I have right here and run it 23 00:02:22,476 --> 00:02:29,373 again there. We can see that it has done what I asked it to do. Is that so? 24 00:02:29,373 --> 00:02:36,270 Well, LS l on find contents should show and yeah, that is so the files are right here. 25 00:02:37,689 --> 00:02:43,467 Now another example is find again sudo find etc. 26 00:02:43,467 --> 00:02:49,245 We start our find operation in the etc directory 27 00:02:49,245 --> 00:02:55,022 name which is looking for all files minus type 28 00:02:55,022 --> 00:03:00,800 f, which goes for files only. 29 00:03:01,699 --> 00:03:04,280 This time I'm going to use xargs. 30 00:03:05,180 --> 00:03:10,300 We'll use the output of the find command to be used as input for the grep command. 31 00:03:10,819 --> 00:03:16,509 I Want to grep on 127001 or whatever text you want to use for 32 00:03:16,509 --> 00:03:22,199 the grep and oh boy, now I'm getting all my error messages. Yeah, that 33 00:03:22,199 --> 00:03:27,889 does make sense because I never used sudo in front of the xargs. 34 00:03:29,349 --> 00:03:34,583 And here we see the result. Well, find first finds files based on all the different properties 35 00:03:34,583 --> 00:03:39,816 of the files and then within these files it's going to use the grep utility, which is 36 00:03:39,816 --> 00:03:45,050 the filtering utility which is checking to see if the text 127001 exists in inside the file. 37 00:03:49,610 --> 00:03:56,379 One more example with find and printf this time so sudo find etc name 38 00:03:56,379 --> 00:04:03,149 I'm looking for vals that have a name ending in any and printf. 39 00:04:05,129 --> 00:04:10,259 I want to do some nice formatting for 40 00:04:10,259 --> 00:04:15,389 these percent s comma percent b n and 41 00:04:15,389 --> 00:04:20,519 then I'm closing my printf string. 42 00:04:21,259 --> 00:04:25,590 Hey, let's also sort that. I'll tell you more about sort later, but 43 00:04:25,590 --> 00:04:29,920 here we can see how the output is actually nothing at all. 44 00:04:30,420 --> 00:04:36,810 Oh boy. Well maybe I should use name instead of ini. 45 00:04:37,610 --> 00:04:41,909 There we can see the different properties that are printed 46 00:04:41,909 --> 00:04:46,209 with this printf command and formatted in nice columns. 47 00:04:47,430 --> 00:04:52,699 That's the end of this video about some advanced usage of the find utility.