1 00:00:00,270 --> 00:00:01,770 Hello there, you beautiful people. 2 00:00:01,770 --> 00:00:03,120 And welcome to part three. 3 00:00:03,120 --> 00:00:06,230 Our final part of our discussion on piping. 4 00:00:06,240 --> 00:00:11,070 Now, in part number one, you learned about the basic concepts of piping and you saw that piping is 5 00:00:11,070 --> 00:00:16,170 all about connecting the standard output of one command to the standard input of another command. 6 00:00:16,170 --> 00:00:21,930 And in part two, you saw how you can actually pass data through your pipeline, but also take snapshots 7 00:00:21,930 --> 00:00:28,140 of the data as it flows through and save those snapshots into a file using something called the T command. 8 00:00:28,140 --> 00:00:33,030 Now the T command is really useful because by doing normal redirection you break your pipeline, but 9 00:00:33,030 --> 00:00:37,680 by using the t command, you can save data but still keep your pipeline flowing. 10 00:00:37,680 --> 00:00:42,270 Now, in part number three, we're going to take that understanding of piping to a whole new level using 11 00:00:42,270 --> 00:00:44,490 something called the x args command. 12 00:00:44,490 --> 00:00:50,250 Now, remember, piping is all about connecting the standard output of one command to the standard input 13 00:00:50,250 --> 00:00:51,270 of another command. 14 00:00:51,540 --> 00:00:55,950 Now, not all commands actually even accept standard input. 15 00:00:55,950 --> 00:00:58,500 Some only accept command line arguments. 16 00:00:58,500 --> 00:01:01,950 And that's exactly where the x args command comes in. 17 00:01:02,070 --> 00:01:09,090 The X Command allows you to convert piped data into command line arguments for commands that only accept 18 00:01:09,090 --> 00:01:14,040 command line arguments so that you can keep your pipe going without having to break it at any point. 19 00:01:14,040 --> 00:01:15,920 So the Exile's Command is that missing piece. 20 00:01:15,930 --> 00:01:18,960 It's going to make your pipelines basically indestructible. 21 00:01:18,960 --> 00:01:20,370 So we're going to teach you how to use that. 22 00:01:20,370 --> 00:01:23,370 And then we're also going to have a summary of piping start to finish. 23 00:01:23,370 --> 00:01:25,890 So make sure that these concepts really, really sink in. 24 00:01:26,040 --> 00:01:30,750 By the end of this video, you're going to be the master of piping concepts after you've probably received 25 00:01:30,750 --> 00:01:35,850 the most comprehensive explanation of it that you'll be able to find anywhere on the Internet. 26 00:01:35,850 --> 00:01:36,960 So there we are, guys. 27 00:01:36,960 --> 00:01:41,460 Let's go ahead and jump right over now into Ubuntu and see this stuff in practice. 28 00:01:43,340 --> 00:01:43,730 Okay. 29 00:01:43,730 --> 00:01:47,040 So let's take a look at how the x args command works. 30 00:01:47,060 --> 00:01:51,650 Let's say that we are again playing around with the date command, for example, and we're getting the 31 00:01:51,650 --> 00:01:54,230 date that's coming out of our system now. 32 00:01:54,770 --> 00:01:59,540 What do you think will happen if we take the date command and we pipe it into Echo? 33 00:01:59,570 --> 00:02:01,130 Now, remember, Echo is very simple. 34 00:02:01,130 --> 00:02:06,170 If I just take echo when I say give echo hello, it'll just say hello back. 35 00:02:06,170 --> 00:02:10,430 So what do you think will happen if I take the date command and pipe that into echo? 36 00:02:11,820 --> 00:02:17,160 Well, you might think that when I press when I press enter the date command will pass on the date into 37 00:02:17,160 --> 00:02:20,730 Echo and it'll spit out the date right and wrong. 38 00:02:20,970 --> 00:02:25,550 Actually, what happened is Echo doesn't accept standard input. 39 00:02:25,560 --> 00:02:29,520 So what happened here, this is a common mistake, actually, that people make when using pipelines 40 00:02:29,520 --> 00:02:30,060 for the first time. 41 00:02:30,060 --> 00:02:32,220 They try to pipe things into Echo. 42 00:02:32,250 --> 00:02:35,680 Now, Echo doesn't accept standard input. 43 00:02:35,700 --> 00:02:38,400 In fact, it only accepts command line arguments. 44 00:02:38,400 --> 00:02:41,340 So if I try to do this and I type to echo, hello again. 45 00:02:41,340 --> 00:02:45,990 Even though I'm piping with the date command into it, if I go ahead and press enter, you can see that 46 00:02:45,990 --> 00:02:49,240 it's only processed its command line arguments. 47 00:02:49,260 --> 00:02:56,430 So the question becomes how could we pass the data from our pipeline into a command that doesn't accept 48 00:02:56,430 --> 00:02:57,870 standard input? 49 00:02:58,380 --> 00:03:05,160 Well, the key is to convert the data from standard input into command line arguments so the command 50 00:03:05,160 --> 00:03:07,370 can continue to work like normal. 51 00:03:07,380 --> 00:03:13,440 So the way that you do that is that instead of pie, instead of piping it into echo directly, you pipe 52 00:03:13,440 --> 00:03:16,470 it into something called the x args command. 53 00:03:16,500 --> 00:03:25,200 Now the x args command will convert the data from standard input and it will put it instead into command 54 00:03:25,200 --> 00:03:26,070 line arguments. 55 00:03:26,070 --> 00:03:33,090 So now I do echo, so I basically put it into x args and then give x args echo to work with. 56 00:03:33,090 --> 00:03:37,830 When I press enter now you can see that now it echoes out the date. 57 00:03:38,160 --> 00:03:38,910 Isn't that cool now? 58 00:03:39,180 --> 00:03:44,760 Now I can also give Echo its own its own command line argument, so I could give it also hello. 59 00:03:44,760 --> 00:03:49,800 And what will happen is it will now process both, except it will process its own command line arguments 60 00:03:49,800 --> 00:03:50,460 first. 61 00:03:50,460 --> 00:03:52,110 So that's something to bear in mind. 62 00:03:52,110 --> 00:03:57,560 But it did indeed echo both of them out, which is a lot better than we had before. 63 00:03:57,570 --> 00:03:58,050 Now. 64 00:03:58,260 --> 00:04:03,540 Now we can actually continue to pipe down because the data that comes out is still on standard output. 65 00:04:03,540 --> 00:04:11,640 So basically x args is like a little plaster or a little fix for when for when a command does not accept 66 00:04:12,000 --> 00:04:15,690 standard does not accept standard input, but only accepts command on arguments. 67 00:04:15,690 --> 00:04:20,490 You can use x args to get around the problem and continue doing your piping. 68 00:04:20,490 --> 00:04:25,820 So let's say that we wanted for it to echo out just the day of the week. 69 00:04:25,830 --> 00:04:30,180 What we could do is we could say date pipe that into the command just like we've been doing a million 70 00:04:30,180 --> 00:04:30,750 times. 71 00:04:30,750 --> 00:04:32,810 Tell it that the delimiter is a space. 72 00:04:32,820 --> 00:04:37,830 Tell it that we want the first field and then you could pipe that into echo. 73 00:04:37,860 --> 00:04:41,970 Now, remember, this isn't going to work because Echo doesn't accept standard input. 74 00:04:41,970 --> 00:04:46,830 So we convert the data from standard input into command line arguments using x args. 75 00:04:46,830 --> 00:04:48,180 Give tell x args. 76 00:04:48,180 --> 00:04:53,940 Hey, we want you to work with echo and now we'll see that it pops out the day of the week, which is 77 00:04:53,940 --> 00:04:54,690 Monday. 78 00:04:55,470 --> 00:04:58,450 So let me give you a bit of an example where this might take you, okay? 79 00:04:58,500 --> 00:05:01,320 This this x args ability, what it might be able to do for you. 80 00:05:01,320 --> 00:05:05,850 So for example, if we take our full data text file, we've got some data in here. 81 00:05:06,480 --> 00:05:08,010 Let me just create a new document here. 82 00:05:08,010 --> 00:05:12,870 I'm going to call it and press control and SX to save. 83 00:05:12,900 --> 00:05:14,010 Yep, that works. 84 00:05:14,010 --> 00:05:20,550 I'm going to call it delete me dot txt so I can make that file. 85 00:05:20,550 --> 00:05:22,320 I've called it delete text. 86 00:05:23,250 --> 00:05:26,070 Now when we look we've got a new file in here called delete my text. 87 00:05:26,190 --> 00:05:31,230 Now there's a command that you'll be coming onto later in the course in the, in the section, all about 88 00:05:31,590 --> 00:05:36,720 navigating the file system and things like that, which is the section after this one. 89 00:05:37,860 --> 00:05:41,040 But there's a command in there called the M command. 90 00:05:41,070 --> 00:05:42,690 Now the R command stands for remove. 91 00:05:42,690 --> 00:05:49,350 It's the command that delete stuff and if I type delete me dot txt and I click enter watch on the left. 92 00:05:49,350 --> 00:05:49,710 Watch. 93 00:05:49,830 --> 00:05:53,490 Just over here you'll notice that the file has just been deleted. 94 00:05:53,520 --> 00:05:59,970 Okay, so you notice here that we actually gave the ah m command a command line argument. 95 00:06:00,210 --> 00:06:02,940 We typed it on the command line, we gave it a file name. 96 00:06:03,120 --> 00:06:07,560 Now what we might want to do is we might want to have another file over here. 97 00:06:07,590 --> 00:06:08,190 Okay. 98 00:06:08,220 --> 00:06:20,190 Called files to delete txt so files to delete txt and in there I'm going to give it the the names of 99 00:06:20,190 --> 00:06:22,710 full data and today dot txt. 100 00:06:22,710 --> 00:06:29,040 So if I put that in there full date txt and we're also going to have what was the other one today dot 101 00:06:29,040 --> 00:06:29,790 txt. 102 00:06:30,930 --> 00:06:33,330 So we've got a file that contains those two names. 103 00:06:34,470 --> 00:06:35,070 Okay. 104 00:06:35,070 --> 00:06:38,340 Now we can read that file out using the cat command. 105 00:06:38,370 --> 00:06:39,360 You've seen this before. 106 00:06:39,630 --> 00:06:45,480 So if I do the cat command and I say files to delete, you see how it gives me the output? 107 00:06:45,930 --> 00:06:49,320 Now I can't just pipe that information into the m command. 108 00:06:49,320 --> 00:06:50,280 Nothing will happen. 109 00:06:50,280 --> 00:06:55,770 Okay, because the RRM command only accepts command line the command line arguments. 110 00:06:55,770 --> 00:07:00,090 But what I can do is I can read the data and we clear the screen. 111 00:07:00,090 --> 00:07:06,210 What I can do is I can read the data from files to delete these file names and pass it into x args. 112 00:07:06,210 --> 00:07:10,830 Now x args is going to convert that data into command line argument. 113 00:07:11,040 --> 00:07:11,880 For the rim commander. 114 00:07:11,880 --> 00:07:15,060 The rim command does accept command line arguments. 115 00:07:15,060 --> 00:07:20,310 So when we do that, notice if I just pipe directly to the rim command, it doesn't work. 116 00:07:20,310 --> 00:07:23,790 It says it's missing an operand, it's missing a command line argument. 117 00:07:24,360 --> 00:07:30,120 But if I type it into the x args command instead and then type M, watch what happens now over at the 118 00:07:30,120 --> 00:07:35,370 left when it's at the command, the files got deleted because now the ah m command could work. 119 00:07:35,370 --> 00:07:36,630 What effectively happened? 120 00:07:36,630 --> 00:07:44,130 It was as if we wrote our m today dot txt and full date SDA actually the other way around because the 121 00:07:44,130 --> 00:07:50,310 file they were written in the other way around in the file it's as if we did this it as if we wrote 122 00:07:50,310 --> 00:07:56,910 out this command, this command here, but instead we just read the file and piped the contents to another 123 00:07:56,910 --> 00:07:57,180 command. 124 00:07:57,180 --> 00:08:02,670 So you can see that this is how you might potentially use the X Command just as a bit of an example, 125 00:08:02,670 --> 00:08:06,930 rather than you just using the date command and echo all the time. 126 00:08:07,740 --> 00:08:11,700 So over the past three videos we've covered a whole lot of stuff. 127 00:08:11,700 --> 00:08:16,200 So let's just try and summarize it all together in one place so that you can feel confident that you've 128 00:08:16,200 --> 00:08:16,860 got it all. 129 00:08:16,890 --> 00:08:22,590 First of all, you learn that piping is a process that connects the standard output of one command to 130 00:08:22,590 --> 00:08:24,300 the standard input of another. 131 00:08:24,300 --> 00:08:30,150 And by the way, if you ever see these two words in orange, stand out an STD in from now on, you know, 132 00:08:30,150 --> 00:08:33,150 that means standard output and standard input respectively. 133 00:08:33,539 --> 00:08:37,110 And STD error is standard error. 134 00:08:37,120 --> 00:08:37,500 Okay. 135 00:08:37,679 --> 00:08:41,760 So if you ever see those things around, so piping connects the standard output of one command to the 136 00:08:41,760 --> 00:08:46,920 standard input of another redirection of standard output breaks pipelines. 137 00:08:46,920 --> 00:08:52,100 So if you're making a pipeline and you do some redirection, you've broken your pipeline, you could 138 00:08:52,290 --> 00:08:55,230 the pipeline from that point on will no longer work. 139 00:08:55,590 --> 00:08:58,800 So standard output has just been redirected into a file by default. 140 00:08:58,800 --> 00:09:01,500 It can't be continued to be passed down the pipeline. 141 00:09:01,500 --> 00:09:04,680 That is unless you use the PT command. 142 00:09:04,680 --> 00:09:10,950 So if you want to save a data snapshot without breaking your pipeline, use the PT command instead and 143 00:09:10,950 --> 00:09:16,980 that will make a basically an imaginary T-junction, just like you might find in pipes of water in your 144 00:09:16,980 --> 00:09:21,690 pipeline so that you can save your data and also have it continue on through the pipeline at the same 145 00:09:21,690 --> 00:09:22,170 time. 146 00:09:22,470 --> 00:09:27,900 Now, if a command doesn't accept standard input, then as we know, piping connect standard output 147 00:09:27,900 --> 00:09:28,620 to standard input. 148 00:09:28,620 --> 00:09:31,110 So how can you still use that command in your pipeline? 149 00:09:31,110 --> 00:09:36,240 Well, if you still want to pipe to it, even if it doesn't accept standard input, as long as the command 150 00:09:36,240 --> 00:09:42,780 accepts command line arguments, you can use the x args command instead and commands that you use with 151 00:09:42,780 --> 00:09:49,950 the x args command can also still have their own command line arguments besides the ones that you pipe 152 00:09:49,950 --> 00:09:52,140 to it so you can still pipe data to it. 153 00:09:52,830 --> 00:09:57,480 You can still pipe data as command on arguments and also give it its own arguments right there on the 154 00:09:57,480 --> 00:09:58,050 command line. 155 00:09:58,050 --> 00:10:02,370 But just understand that the ones that you type to it on the command line will be processed first. 156 00:10:02,370 --> 00:10:04,980 So that's a whole bunch of stuff, guys. 157 00:10:05,550 --> 00:10:11,220 This really is the most important part of getting good at the Linux command line. 158 00:10:11,220 --> 00:10:17,430 If you can understand and you feel confident in what you've learned in the last three videos about piping, 159 00:10:17,460 --> 00:10:23,430 you have unlocked the crown jewel of using the Linux command line and you should be massively proud 160 00:10:23,430 --> 00:10:23,970 of yourself. 161 00:10:23,970 --> 00:10:25,980 And if you haven't, then just go back. 162 00:10:25,980 --> 00:10:29,280 Watch these videos as many times as it takes for you to get it down. 163 00:10:29,280 --> 00:10:34,560 Take some notes, practice, try stuff out, because I promise you the effort will be worth it. 164 00:10:34,560 --> 00:10:38,540 And I'm really proud of you for actually making it this far, and so should you as well. 165 00:10:38,550 --> 00:10:43,080 Now, up next, we're going to show you a little trick that's going to make your use of the command 166 00:10:43,080 --> 00:10:44,250 line a whole lot easier. 167 00:10:44,250 --> 00:10:48,990 And we're going to show you how you can use something called aliases to save your command pipelines 168 00:10:48,990 --> 00:10:53,340 with easy to remember names so they can be just used much easier later on. 169 00:10:53,340 --> 00:10:56,070 So once you've written a pipeline, you don't have to write it again. 170 00:10:56,070 --> 00:10:59,850 Just use the name and it will come up without any errors. 171 00:10:59,850 --> 00:11:05,370 So for all that good stuff to learn about aliases and making shortcuts, I'll see you in the next video.