1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,259 --> 00:00:06,209 Now you know what is 'xargs' command, 3 00:00:06,239 --> 00:00:08,159 and how you could use it with 4 00:00:08,159 --> 00:00:11,189 piping. Now, let's suppose that we 5 00:00:11,219 --> 00:00:13,889 have following task. We need to find 6 00:00:13,919 --> 00:00:16,739 all directories that have "kernel" 7 00:00:16,768 --> 00:00:19,649 somewhere in their names; and 8 00:00:19,649 --> 00:00:22,319 afterwards we want to list all 9 00:00:22,319 --> 00:00:24,569 files and directories in those 10 00:00:24,599 --> 00:00:28,349 found directories. For that, we can 11 00:00:28,349 --> 00:00:31,439 use 'ls' command combined with 'find' 12 00:00:31,439 --> 00:00:34,019 command. First we'll find all 13 00:00:34,049 --> 00:00:35,729 directories that contain somewhere 14 00:00:35,729 --> 00:00:37,679 "kernel'; and afterwards we will 15 00:00:37,679 --> 00:00:40,409 execute 'ls' command. Let's try to use 16 00:00:40,409 --> 00:00:43,349 an 'exec' option in 'find' command. All 17 00:00:43,349 --> 00:00:46,469 right. 'find', and let's look for such 18 00:00:46,469 --> 00:00:48,749 folders in all folders, here will be 19 00:00:48,779 --> 00:00:50,639 absolute path to root folder, 20 00:00:51,029 --> 00:00:53,699 '/'. Next, I am looking for 21 00:00:53,699 --> 00:00:56,309 folders that have somewhere "kernel" 22 00:00:56,339 --> 00:00:58,889 like so, here will be '-name' option. 23 00:00:59,459 --> 00:01:01,769 Next, I say that I want to search 24 00:01:01,829 --> 00:01:04,229 only for directories '-type d'. 25 00:01:04,709 --> 00:01:07,589 Next, comes 'exec' option, and here we 26 00:01:07,589 --> 00:01:09,809 will execute 'ls' command that will 27 00:01:09,809 --> 00:01:11,909 list all files and folders inside 28 00:01:11,909 --> 00:01:14,849 of the found directories. 'exec ls 29 00:01:15,149 --> 00:01:18,509 -l', we'll say; here will be also 30 00:01:18,569 --> 00:01:21,179 '--color' option in order to see color 31 00:01:21,209 --> 00:01:23,339 output; here will be pair of curly 32 00:01:23,339 --> 00:01:25,559 braces; and in this case 'ls' command 33 00:01:25,589 --> 00:01:27,809 will be run multiple times 34 00:01:27,809 --> 00:01:29,279 depending on the quantity of the 35 00:01:29,279 --> 00:01:31,979 found directories. And finally, it 36 00:01:31,979 --> 00:01:34,199 will be a '\;'. And 37 00:01:34,199 --> 00:01:36,479 it will be last argument for 'exec' 38 00:01:36,509 --> 00:01:38,369 option. Here are actually all 39 00:01:38,399 --> 00:01:40,229 arguments that will be used for 40 00:01:40,259 --> 00:01:42,899 '-exec' option. All right, let's 41 00:01:42,899 --> 00:01:46,769 press Enter, and see results. And 42 00:01:46,799 --> 00:01:49,109 actually, I see such sections as 43 00:01:49,139 --> 00:01:52,889 this one, this one, let me scroll a 44 00:01:52,889 --> 00:01:55,859 bit up, here was one more large 45 00:01:55,859 --> 00:01:58,589 section, and so on. Different 46 00:01:58,589 --> 00:02:01,109 sections, one section per found 47 00:02:01,109 --> 00:02:03,869 folder. Actually, let me remove 48 00:02:03,899 --> 00:02:06,449 temporarily this '-exec' part, like 49 00:02:06,479 --> 00:02:09,389 so, and execute it without '-exec' 50 00:02:09,389 --> 00:02:11,579 option. And you see that in my 51 00:02:11,579 --> 00:02:15,089 case, I have found the 1, 2, 3, 5 folders 52 00:02:15,179 --> 00:02:17,309 that have "kernel" somewhere in their 53 00:02:17,309 --> 00:02:19,859 name. And here you see all paths to 54 00:02:19,889 --> 00:02:21,749 those folders - '/etc/kernel', 55 00:02:21,869 --> 00:02:25,229 'proc/sys/kernel', and so on. And 56 00:02:25,229 --> 00:02:27,779 actually here we see contents of 57 00:02:27,809 --> 00:02:30,089 every such folder. For example, 58 00:02:30,119 --> 00:02:32,009 let's list files and folders here 59 00:02:32,039 --> 00:02:34,109 in this directory. Let me copy it, 60 00:02:34,319 --> 00:02:37,409 paste, and I see same result as I 61 00:02:37,409 --> 00:02:40,049 have seen here in this section. But 62 00:02:40,049 --> 00:02:41,819 notice that in this output, we 63 00:02:41,849 --> 00:02:44,369 don't see actually path to every 64 00:02:44,399 --> 00:02:45,989 directory we are currently 65 00:02:45,989 --> 00:02:48,539 processing. Recap that in this 66 00:02:48,539 --> 00:02:50,969 command, let me go back to it, each 67 00:02:50,999 --> 00:02:53,669 found directory will be sent as 68 00:02:53,699 --> 00:02:57,824 argument here to 'ls -l --color' 69 00:02:57,824 --> 00:03:00,839 command. Alright, now let's 70 00:03:00,839 --> 00:03:04,409 try to use pipe operator and 'xargs' 71 00:03:04,409 --> 00:03:06,509 command in order to perform same 72 00:03:06,509 --> 00:03:09,419 action. I'll simply remove this 73 00:03:09,419 --> 00:03:12,209 part with 'exec' operator; then I'll 74 00:03:12,209 --> 00:03:14,694 add pipe, '|' operator, here will be 75 00:03:14,694 --> 00:03:18,719 'xargs', like so; next, will be 'ls - 76 00:03:18,749 --> 00:03:21,359 l'; and '--color' option. 77 00:03:22,259 --> 00:03:24,209 Let's execute this command now and 78 00:03:24,209 --> 00:03:28,349 see results. And now I see that all 79 00:03:28,349 --> 00:03:30,419 files and folders of every found 80 00:03:30,419 --> 00:03:32,549 directory are grouped per 81 00:03:32,579 --> 00:03:35,489 path. For example, here I see files 82 00:03:35,489 --> 00:03:36,869 and folders located in this 83 00:03:36,869 --> 00:03:39,419 path. There is one file 'uevent', 84 00:03:39,569 --> 00:03:42,269 and one folder 'parameters'. Same 85 00:03:42,299 --> 00:03:44,699 I see for other directories. For 86 00:03:44,699 --> 00:03:47,339 example, '/sys/kernel', '/root/etc- 87 00:03:47,339 --> 00:03:51,089 backup-2/kernel' and so on. And 88 00:03:51,089 --> 00:03:53,009 that means that now we see actually 89 00:03:53,009 --> 00:03:54,899 result that differ from the 90 00:03:54,899 --> 00:03:56,729 results that we have received with 91 00:03:56,759 --> 00:04:00,569 'exec' option for 'find' command. And 92 00:04:00,599 --> 00:04:02,909 actually here what happened? We 93 00:04:03,149 --> 00:04:06,359 send results of 'find' command as 94 00:04:06,359 --> 00:04:08,849 arguments using 'xargs' command to 95 00:04:08,879 --> 00:04:11,309 this command; and this command has 96 00:04:11,339 --> 00:04:13,439 executed actually multiple times, 97 00:04:13,529 --> 00:04:16,228 in this case five times. And we 98 00:04:16,228 --> 00:04:18,449 have seen results grouped by 99 00:04:18,449 --> 00:04:21,040 specific directory name like, '/etc/kernel', 100 00:04:21,040 --> 00:04:23,219 '/proc/sys/kernel', and so on. 101 00:04:24,329 --> 00:04:26,039 That's how you could combine the 102 00:04:26,039 --> 00:04:28,540 'find' command, pipe, '|' operator, and 103 00:04:28,540 --> 00:04:31,439 'xargs' command. Alright guys, that's 104 00:04:31,439 --> 00:04:32,669 all for this lecture. I hope you 105 00:04:32,669 --> 00:04:34,289 enjoyed this example. And now you 106 00:04:34,289 --> 00:04:36,629 understand how to use pipe, 'xargs', 107 00:04:36,689 --> 00:04:39,719 'find' and other comments. And that's 108 00:04:39,719 --> 00:04:41,819 all for 'find' command. I have given 109 00:04:41,819 --> 00:04:43,919 you some examples. 'find' command is 110 00:04:43,949 --> 00:04:45,899 very useful; and it has many, many 111 00:04:45,899 --> 00:04:47,429 different options; and I hope 112 00:04:47,429 --> 00:04:49,019 you'll explore some additional 113 00:04:49,019 --> 00:04:51,419 options on your own. Now, let's go 114 00:04:51,419 --> 00:04:52,979 on, and next let's talk about 115 00:04:52,979 --> 00:04:54,659 compression in Linux, and I'll 116 00:04:54,659 --> 00:04:57,269 explain you how to zip and unzip 117 00:04:57,269 --> 00:04:58,949 different files and folders. I'll 118 00:04:58,949 --> 00:04:59,969 see you next. Bye-Bye. 119 00:04:59,969 --> 00:05:03,061 [no audio]