1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,380 --> 00:00:05,790 So far we have talked about 3 00:00:05,820 --> 00:00:07,530 different Linux features, about 4 00:00:07,530 --> 00:00:09,900 management of directories files, 5 00:00:09,930 --> 00:00:12,240 about Linux soft and hard, and so 6 00:00:12,240 --> 00:00:14,490 on. And now it's time to talk about 7 00:00:14,490 --> 00:00:16,680 the 'find' command. And using this 8 00:00:16,680 --> 00:00:18,540 command you could easily and fast 9 00:00:18,690 --> 00:00:21,060 find different files and folders 10 00:00:21,090 --> 00:00:23,340 using different filter criteria. 11 00:00:24,270 --> 00:00:25,830 And first of all please verify 12 00:00:25,830 --> 00:00:27,480 whether 'find' is available in 13 00:00:27,480 --> 00:00:29,970 command line. Please type 'find'; and 14 00:00:29,970 --> 00:00:32,100 yes this command is available. And 15 00:00:32,100 --> 00:00:34,320 as you see when you simply enter a 16 00:00:34,320 --> 00:00:36,840 'find' command you already see some 17 00:00:36,840 --> 00:00:39,270 results. And basically in this 18 00:00:39,270 --> 00:00:42,420 case, you see all files and folders 19 00:00:42,540 --> 00:00:44,280 that are located in current 20 00:00:44,310 --> 00:00:46,140 directory. And at the moment the 21 00:00:46,140 --> 00:00:48,210 current directory is home directory 22 00:00:48,240 --> 00:00:50,250 for this particular user, it is 23 00:00:50,280 --> 00:00:53,220 '/root'. And here above you see 24 00:00:53,220 --> 00:00:56,070 a whole list of all files located 25 00:00:56,100 --> 00:00:59,520 in this folder. And recap that 26 00:00:59,520 --> 00:01:01,500 we have created several files 27 00:01:01,530 --> 00:01:03,690 and directories before. Let me 28 00:01:03,690 --> 00:01:06,629 list them as 'ls -la'; and I see for 29 00:01:06,629 --> 00:01:07,900 example such folder as 30 00:01:07,900 --> 00:01:11,100 'etc-backup-2'; and actually 31 00:01:11,190 --> 00:01:13,890 this folder was copied from 'etc' 32 00:01:13,890 --> 00:01:16,260 folder. Also, before we have created 33 00:01:16,290 --> 00:01:18,708 such files as 'file1.txt', 34 00:01:18,708 --> 00:01:21,480 'file2.txt', and so on. 'find' command 35 00:01:21,510 --> 00:01:24,300 is very, very powerful; and it has 36 00:01:24,330 --> 00:01:26,250 a lot of different options. And 37 00:01:26,250 --> 00:01:28,080 before showing you some examples, 38 00:01:28,170 --> 00:01:30,900 please open up 'man pages' for this 39 00:01:30,900 --> 00:01:32,670 command. Open up Google Chrome; and 40 00:01:32,670 --> 00:01:35,280 type here 'man pages find'; and click 41 00:01:35,280 --> 00:01:38,190 on this first link; and here you'll 42 00:01:38,190 --> 00:01:40,410 see description of this 'find' the 43 00:01:40,410 --> 00:01:42,840 command. And it is used for search 44 00:01:42,840 --> 00:01:45,900 of files and directories. Here is a 45 00:01:45,900 --> 00:01:47,520 large description of this command, 46 00:01:47,550 --> 00:01:49,380 and afterwards you see some 47 00:01:49,410 --> 00:01:51,960 options. And here's the difference 48 00:01:51,990 --> 00:01:53,940 between the 'find' and other commands 49 00:01:53,970 --> 00:01:56,220 that we have used before. 'find' 50 00:01:56,220 --> 00:01:58,680 command has regular options like 51 00:01:58,710 --> 00:02:02,400 '-P', capital P, '-L', and 52 00:02:02,400 --> 00:02:05,430 so on. But it also has additional 53 00:02:05,460 --> 00:02:07,950 options that come after argument. 54 00:02:08,430 --> 00:02:10,770 And this part of command is called 55 00:02:10,830 --> 00:02:11,830 Expression. 56 00:02:13,139 --> 00:02:15,030 Argument for 'find' command is 57 00:02:15,030 --> 00:02:16,950 actually path to a specific 58 00:02:16,950 --> 00:02:19,530 folder. For example, as argument 59 00:02:19,560 --> 00:02:22,560 you could use '.'; 'find' and '.'. '.' 60 00:02:22,560 --> 00:02:24,840 here is argument for 'find' command. 61 00:02:25,380 --> 00:02:27,030 Or you could use as argument for 62 00:02:27,030 --> 00:02:30,210 example, such path, '/bin'. 63 00:02:30,210 --> 00:02:31,980 Or you could use the relative path 64 00:02:32,010 --> 00:02:34,770 like '../', and so on. It 65 00:02:34,770 --> 00:02:37,440 is argument for 'find' command. But 66 00:02:37,440 --> 00:02:39,180 after argument, you could use 67 00:02:39,240 --> 00:02:41,040 additional options that are 68 00:02:41,040 --> 00:02:44,280 available only in 'find' command. And 69 00:02:44,310 --> 00:02:46,710 this part that comes after this 70 00:02:46,740 --> 00:02:49,200 argument, after path is called 71 00:02:49,230 --> 00:02:52,500 expression. An expression consists 72 00:02:52,560 --> 00:02:54,660 of multiple options, and you could 73 00:02:54,660 --> 00:02:55,920 use multiple options 74 00:02:55,950 --> 00:02:58,470 simultaneously. For example, if you 75 00:02:58,500 --> 00:03:00,330 scroll down, you'll see such 76 00:03:00,360 --> 00:03:02,857 options as '-daystart', 77 00:03:02,857 --> 00:03:08,400 '-follow', '-regextype', and so on. And 78 00:03:08,400 --> 00:03:10,020 please notice here difference 79 00:03:10,020 --> 00:03:11,790 between options that we have used 80 00:03:11,790 --> 00:03:13,470 and discussed before, and those 81 00:03:13,500 --> 00:03:15,930 options. I have told you before that 82 00:03:15,960 --> 00:03:18,780 single dash is used with single 83 00:03:18,780 --> 00:03:21,400 character options like '-l', '-c', 84 00:03:21,400 --> 00:03:23,200 and so on. But here you see 85 00:03:23,250 --> 00:03:25,710 that here long versions of options 86 00:03:25,710 --> 00:03:28,350 like 'daystart' are used with single 87 00:03:28,380 --> 00:03:31,050 dash, and that's because those 88 00:03:31,080 --> 00:03:32,760 options are called positional 89 00:03:32,790 --> 00:03:35,040 options, and they are used inside 90 00:03:35,040 --> 00:03:37,560 of the expression that comes after 91 00:03:37,590 --> 00:03:39,360 arguments inside of the 'find' 92 00:03:39,360 --> 00:03:41,700 command. All right, that is the 93 00:03:41,700 --> 00:03:43,680 structure of the 'find' command. It 94 00:03:43,680 --> 00:03:45,300 contains a regular options, 95 00:03:45,480 --> 00:03:47,940 argument, and additional expression 96 00:03:47,970 --> 00:03:49,950 that contains different options 97 00:03:49,980 --> 00:03:52,800 like 'daystart', and so on. If you 98 00:03:52,830 --> 00:03:54,780 scroll down here, you may find a 99 00:03:54,810 --> 00:03:57,660 bunch of such kind of options like 100 00:03:57,660 --> 00:03:59,880 'maxdepth', 'mindepth', 'mount', and so 101 00:03:59,880 --> 00:04:02,700 on. And if you scroll down, you may 102 00:04:02,700 --> 00:04:06,180 find some examples of usage of this 103 00:04:06,210 --> 00:04:09,120 'find' command. Here they're. And for 104 00:04:09,120 --> 00:04:11,610 example, in this command, this 105 00:04:11,640 --> 00:04:14,760 '/tmp' is actually argument; and 106 00:04:14,760 --> 00:04:16,950 after argument, you see multiple 107 00:04:16,980 --> 00:04:19,230 operators. Here's operator 108 00:04:19,230 --> 00:04:21,209 '-name', here's one more operator 109 00:04:21,209 --> 00:04:22,950 '-type', and here's additional 110 00:04:22,950 --> 00:04:25,800 operator '-print'. Notice that some 111 00:04:25,800 --> 00:04:28,230 of those operators may have own 112 00:04:28,260 --> 00:04:31,170 arguments, and 'core' here is argument 113 00:04:31,200 --> 00:04:34,710 for this '-name' operator; 'f' is 114 00:04:34,740 --> 00:04:36,777 argument for this operator, 115 00:04:36,777 --> 00:04:39,480 '-type'; and '-print' doesn't have 116 00:04:39,510 --> 00:04:42,900 any operators. Also if you want you 117 00:04:42,900 --> 00:04:46,110 could pipe result of 'find' command by 118 00:04:46,140 --> 00:04:49,200 stdout to stdin of another 119 00:04:49,200 --> 00:04:51,300 command. And in one of the next 120 00:04:51,300 --> 00:04:52,950 lectures I will explain you what is 121 00:04:52,980 --> 00:04:55,830 'xargs' here. For now, please 122 00:04:55,830 --> 00:04:58,140 understand that 'find' contains 123 00:04:58,320 --> 00:05:00,660 non-traditional arguments; and they 124 00:05:00,660 --> 00:05:03,150 come after argument that is 125 00:05:03,150 --> 00:05:05,250 actually path to specific folder. 126 00:05:06,360 --> 00:05:08,040 Alright, now let's dive into 127 00:05:08,040 --> 00:05:09,900 examples; and let's examine 128 00:05:10,050 --> 00:05:12,060 capabilities of 'find' command. But 129 00:05:12,060 --> 00:05:13,200 let's proceed with that after the 130 00:05:13,200 --> 00:05:14,790 small pause. See you next. Bye. 131 00:05:14,790 --> 00:05:17,098 [no audio]