1 00:00:06,519 --> 00:00:08,080 This video is about xargs. 2 00:00:08,939 --> 00:00:12,589 So xargs is used to build commands dynamically from the standard input. 3 00:00:13,869 --> 00:00:20,500 Normally it gets its input from a pipe and it allows commands that don't support piped input to work with 4 00:00:20,500 --> 00:00:27,129 other commands. Anyway, it's a little bit like what we have seen in find exec, but xarc is is faster 5 00:00:27,129 --> 00:00:33,759 and more flexible than find exec for the simple reason that xarcs works on other commands as well. 6 00:00:35,740 --> 00:00:39,730 If multiple arguments are passed through a command that supports one single argument 7 00:00:39,730 --> 00:00:43,719 only, you can use N1 to process the arguments one by one. 8 00:00:44,740 --> 00:00:50,216 So that means that you are not going to use echolisalinda, lori, 9 00:00:50,216 --> 00:00:55,693 pipexargs user@ but echo lisa, linda, laurie, pipe xarx n1userad there are 10 00:00:55,693 --> 00:01:01,170 some commands that are a bit problematic with xargs like ls. 11 00:01:01,909 --> 00:01:05,560 So for that reason don't try to use xargs together with ls. 12 00:01:05,560 --> 00:01:09,210 Better use find instead. Let's have a look at some examples. 13 00:01:10,950 --> 00:01:14,250 So for the first example I'm going to create a couple of files. 14 00:01:16,170 --> 00:01:20,079 Let's use touch one ten log. 15 00:01:24,620 --> 00:01:30,100 So I now created a couple of files that 16 00:01:30,100 --> 00:01:35,580 have the extension log and just to explain how 17 00:01:35,580 --> 00:01:41,060 it works, I'm using LFS log on xargs RM 18 00:01:41,060 --> 00:01:46,540 f and the result all these cells are gone. 19 00:01:47,519 --> 00:01:52,349 Now this example is not so very powerful because you might wonder why didn't 20 00:01:52,349 --> 00:01:57,180 you just use rmstar log? And yeah, that would have worked as well. 21 00:01:57,859 --> 00:02:03,520 But to understand how xargs is taking input from a pipe, it's useful because 22 00:02:03,520 --> 00:02:09,180 normally RM f needs an argument and this argument is provided dynamically by xargs. 23 00:02:10,099 --> 00:02:13,719 Another example, let's do a sudo now. 24 00:02:14,620 --> 00:02:16,080 You know what, let's do something else. 25 00:02:16,620 --> 00:02:21,569 Ddif is dev0of is big 26 00:02:21,569 --> 00:02:26,519 file 1bs is 125m, only 27 00:02:26,520 --> 00:02:31,469 24. That also works. 28 00:02:32,129 --> 00:02:36,629 So what is this command doing? Well, this command is creating a 29 00:02:36,629 --> 00:02:41,129 file with the name bigfile1 and oops, I did it wrong. 30 00:02:41,669 --> 00:02:47,550 I forgot to specify how many blocks it should copy. But hey, it did create a file 31 00:02:47,550 --> 00:02:53,430 with the name big file1 and as you can see, this big file1 is really big. 32 00:02:55,129 --> 00:03:01,530 Now I'm going to use find.type f size +100m followed by 33 00:03:01,530 --> 00:03:07,930 xarcs. Well, on the slide I'm using MV to move it, 34 00:03:07,930 --> 00:03:14,330 but here I better use RM F to remove it. 35 00:03:15,930 --> 00:03:21,090 As a result, we don't have bakefile anymore. And let's do a quick df 36 00:03:21,090 --> 00:03:26,250 h to verify that I still have 12 gigabytes available. Phew, that works. 37 00:03:27,370 --> 00:03:32,840 Now let's use another one and this other one is 38 00:03:32,840 --> 00:03:38,310 echo linda lisa laurie 5 sudo xrgs we need sudo 39 00:03:38,310 --> 00:03:43,780 this time because I'm going to create some users. 40 00:03:45,439 --> 00:03:52,235 N1 to user add sudo requires a sudo password. It does give an error on user 41 00:03:52,235 --> 00:03:59,030 Linda because that user already existed. But users Lisa and Lori have successfully been created. 42 00:03:59,629 --> 00:04:06,375 I can use a quick test to verify using til n3 on etc passwd that's showing the 43 00:04:06,375 --> 00:04:13,120 last three lines in the passwd file showing that the users have indeed been successfully created. 44 00:04:13,699 --> 00:04:14,360 That's xargs.