1 00:00:00,360 --> 00:00:01,920 Hello the beautiful people. 2 00:00:01,920 --> 00:00:02,969 And welcome back. 3 00:00:02,969 --> 00:00:08,710 I left you with a bit of a cliffhanger in the last video where you learned all about the basics of piping. 4 00:00:08,730 --> 00:00:13,080 Now, in this video, we're going to take what you learned about the basics in the previous video. 5 00:00:13,080 --> 00:00:17,910 And in this video, we're going to level it up and teach you some advanced piping techniques. 6 00:00:17,910 --> 00:00:22,230 So with the basic stuff you learned last in the last video about just taking the output of one command 7 00:00:22,230 --> 00:00:27,420 and piping it directly into the input, into the standard input of another, that doesn't leave much 8 00:00:27,420 --> 00:00:31,380 room for flexibility, whereas there's loads of really cool things that you can do with your pipelines 9 00:00:31,380 --> 00:00:33,540 if you learn just a few more techniques. 10 00:00:33,540 --> 00:00:37,500 So in this video, we're going to go over those advanced piping techniques and by the end, you know 11 00:00:37,500 --> 00:00:42,300 how to make advanced pipelines using the T and X args commands. 12 00:00:42,300 --> 00:00:44,550 So let's go ahead and jump into it. 13 00:00:45,840 --> 00:00:46,410 All right. 14 00:00:46,410 --> 00:00:49,370 So let's just have a quick recap of what we did in the last video. 15 00:00:49,380 --> 00:00:54,150 So in the last video, we use the data command to get loads of system information about our computers 16 00:00:54,150 --> 00:00:54,740 clock. 17 00:00:54,750 --> 00:01:00,690 And what we did was we passed that data into the cut command because we just wanted to cut out the day 18 00:01:00,690 --> 00:01:02,670 of the week, which is a monday. 19 00:01:02,700 --> 00:01:08,070 Now to cut out the day of the week, we have to say that this data is actually broken up into several 20 00:01:08,070 --> 00:01:11,100 columns and each column is separated by a space. 21 00:01:11,130 --> 00:01:17,040 Now, another way of saying that is that each column is delimited by a space as a fancy word in computer 22 00:01:17,040 --> 00:01:17,790 lingo. 23 00:01:18,120 --> 00:01:24,660 And so what we did is we gave the the cut command a delimiter, and we said the delimiter is a space. 24 00:01:25,560 --> 00:01:30,630 And now once we've said, okay, each column is split up by bi spaces, which field do we want? 25 00:01:30,630 --> 00:01:31,470 Which column do we want? 26 00:01:31,500 --> 00:01:33,750 What is the first column now? 27 00:01:33,750 --> 00:01:38,400 Fields in the command are called sorry, what columns in the command are called Fields. 28 00:01:38,400 --> 00:01:41,280 So we just said fields equals one. 29 00:01:41,280 --> 00:01:44,880 And when we press enter, that cuts out Monday. 30 00:01:45,210 --> 00:01:47,250 So that's what we did in the last video. 31 00:01:47,250 --> 00:01:49,050 Then I gave you a little bit of a challenge. 32 00:01:49,050 --> 00:01:57,450 I said, Hey, how can we go about actually saving this information into a file but at the same time 33 00:01:57,450 --> 00:02:00,210 also pass it down into the pipeline? 34 00:02:00,210 --> 00:02:05,640 So how can we save it into a file, but also pass it down into the cut command so that it can be operated 35 00:02:05,640 --> 00:02:07,470 on so we can get Monday out. 36 00:02:07,470 --> 00:02:09,330 So we're trying to do two things at once. 37 00:02:09,330 --> 00:02:14,010 So to do that, we actually need to have another command called the T command. 38 00:02:14,010 --> 00:02:16,920 So let's take a look at how the PT command works. 39 00:02:18,100 --> 00:02:20,390 So here's an image of how the T command works. 40 00:02:20,410 --> 00:02:24,850 Now I'll put a link to the original picture in the video resources, but you can see here that we have 41 00:02:24,850 --> 00:02:26,650 a pipe between two commands. 42 00:02:26,650 --> 00:02:30,760 So here's a command over on the left and we have another command over here on the right. 43 00:02:30,760 --> 00:02:32,860 And in the middle we're using the PT command. 44 00:02:33,310 --> 00:02:35,880 Now, we haven't covered what these specific commands do. 45 00:02:35,890 --> 00:02:37,330 It doesn't actually matter so much. 46 00:02:37,330 --> 00:02:41,320 What I want you to focus on is the PT command in the middle and just understand that we're trying to 47 00:02:41,320 --> 00:02:48,190 pipe two commands together now, just like a t junction in a pipe of water, we can use the PT command 48 00:02:48,190 --> 00:02:50,530 to cause our data to flow into directions. 49 00:02:50,530 --> 00:02:57,480 We can cause it to flow horizontally as well as flow vertically downwards into other files. 50 00:02:57,490 --> 00:02:58,900 You can imagine it working like that. 51 00:02:59,320 --> 00:03:04,450 So this, the PT command allows us to pass the data on to the rest of the pipe, but it also allows 52 00:03:04,450 --> 00:03:06,520 us to keep it in a file. 53 00:03:06,940 --> 00:03:11,500 So you can see here that we've got a command on the left that is trying to pipe its data across into 54 00:03:11,500 --> 00:03:12,730 another command on the right. 55 00:03:12,820 --> 00:03:17,230 In the middle, though, we pipe it through the PT command and the PT command, we give it a command 56 00:03:17,230 --> 00:03:21,430 line argument of file txt that could be any file name that you want. 57 00:03:21,640 --> 00:03:25,900 And what happens is the data does pass all the way through from the standard output of one command to 58 00:03:25,900 --> 00:03:26,980 the standard input or the other. 59 00:03:26,980 --> 00:03:28,930 But it also falls down. 60 00:03:28,930 --> 00:03:34,960 You can imagine it falling down from your command line into a file called file that txt or whatever 61 00:03:34,960 --> 00:03:37,090 file name you gave the PT command. 62 00:03:37,270 --> 00:03:39,340 So that's how the PT command works. 63 00:03:39,340 --> 00:03:41,320 In theory, this is how this graphic works. 64 00:03:41,650 --> 00:03:44,020 Let's go ahead and see it work in practice. 65 00:03:45,510 --> 00:03:45,780 Okay. 66 00:03:45,870 --> 00:03:49,860 So now that you understand how the PT command works, let's just have a quick refresher of our command 67 00:03:49,860 --> 00:03:50,570 pipeline. 68 00:03:50,580 --> 00:03:55,110 We have the date command, which gives us a whole bunch of information about our systems clock. 69 00:03:55,110 --> 00:03:59,640 And we wanted to cut out the Monday or whatever day of the week it actually is. 70 00:04:00,000 --> 00:04:03,230 So we take the date command and we piped it into the cut command. 71 00:04:03,240 --> 00:04:07,890 Now we notice that the data is broken up into columns that are separated by spaces. 72 00:04:07,890 --> 00:04:10,080 So we say, Hey, cut command, we have a delimiter. 73 00:04:10,080 --> 00:04:10,890 That's a space. 74 00:04:10,890 --> 00:04:15,780 The data is delimited by spaces and we want the first column or as the command calls it, the first 75 00:04:15,780 --> 00:04:16,350 field. 76 00:04:16,350 --> 00:04:19,620 And that gives us the day of the week, which in this case is Monday. 77 00:04:19,649 --> 00:04:26,250 Now, the challenge was we want to not only have that come out, we also want to save the entire date 78 00:04:27,060 --> 00:04:32,010 into a file called called full date txt. 79 00:04:32,490 --> 00:04:33,990 So here's how we would do that. 80 00:04:33,990 --> 00:04:36,450 I'm going to press the up arrow key to get where we got before. 81 00:04:37,380 --> 00:04:41,160 Now what I'm going to do is I'm just going to squeeze in here the t command. 82 00:04:41,190 --> 00:04:41,560 Okay? 83 00:04:41,700 --> 00:04:46,560 Now the t command is going to put one of those like T junctions in our pipeline. 84 00:04:46,560 --> 00:04:47,910 You need to imagine it in your head. 85 00:04:47,910 --> 00:04:48,260 Okay. 86 00:04:48,330 --> 00:04:53,250 So what's going to happen is the data is going to pass all the way through the pipeline horizontally. 87 00:04:53,250 --> 00:04:58,200 So it's going to pass from the date command standard output and go into the standard input of the cut 88 00:04:58,230 --> 00:04:58,530 command. 89 00:04:58,530 --> 00:05:00,510 So it's going to flow straight the way through. 90 00:05:00,540 --> 00:05:06,240 But now what the T command is going to do is it's going to allow us to save the data vertically downwards. 91 00:05:06,240 --> 00:05:10,290 So you can imagine it being like a big letter T, like a big T junction. 92 00:05:10,530 --> 00:05:17,400 The data is going to go downwards into the file called full date dot txt. 93 00:05:18,360 --> 00:05:18,930 So here we are. 94 00:05:18,930 --> 00:05:20,550 The data is going to go horizontally down. 95 00:05:20,550 --> 00:05:20,820 Oops. 96 00:05:20,820 --> 00:05:23,850 I've opened a new term for my bad that is going to go horizontally across. 97 00:05:23,880 --> 00:05:24,320 Okay. 98 00:05:24,450 --> 00:05:30,480 And it's also going to go vertically downwards into a file called full data txt. 99 00:05:30,690 --> 00:05:36,000 So when we do that, we see that the output of the day of the week has still happened because that was 100 00:05:36,000 --> 00:05:39,960 passed through the cut command of the cut command, spit it out to its standard output, which is still 101 00:05:39,960 --> 00:05:41,100 connected to our terminal. 102 00:05:41,100 --> 00:05:46,990 But when we open up our file explorer, we can see that now we have a file called Full Data. 103 00:05:47,080 --> 00:05:51,870 TXT I deleted all of the other ones we had before, so we were starting afresh and now we have full 104 00:05:51,870 --> 00:05:52,540 data. 105 00:05:52,620 --> 00:05:59,130 TXT now when I open that well hey we can actually see that all of the data data has been indeed saved 106 00:05:59,130 --> 00:06:01,770 in a file called full date dot txt. 107 00:06:01,800 --> 00:06:02,610 Isn't that awesome? 108 00:06:02,610 --> 00:06:03,060 That's proper. 109 00:06:03,060 --> 00:06:03,300 Cool. 110 00:06:03,300 --> 00:06:03,480 Right. 111 00:06:03,480 --> 00:06:08,610 So what happened was the date command spat out all of its information all the way across the pipeline. 112 00:06:08,670 --> 00:06:13,020 And when it got to the T command, the T commanders took a snapshot of the data in the pipeline and 113 00:06:13,020 --> 00:06:16,680 passed it down into a file called full date txt. 114 00:06:16,680 --> 00:06:20,670 So that file contains all of the data that's coming out of the date command. 115 00:06:21,150 --> 00:06:26,520 But then the data was passed on into the cut command which did some processing and that spat out the 116 00:06:26,520 --> 00:06:28,680 day of the week, which in this case was Monday. 117 00:06:28,770 --> 00:06:30,300 Now, I've got a quick challenge for you. 118 00:06:30,300 --> 00:06:30,630 Okay? 119 00:06:30,750 --> 00:06:32,010 And I think you can do it. 120 00:06:32,010 --> 00:06:37,710 What I want you to do is I want you to instead of having the the day of the week spit out to the terminal, 121 00:06:37,860 --> 00:06:44,820 I want you to see if you can figure out how you can use redirection to actually cause that data to be 122 00:06:44,820 --> 00:06:48,240 saved in a file called today dot txt. 123 00:06:48,760 --> 00:06:48,950 Okay. 124 00:06:49,230 --> 00:06:53,820 So instead of having the day of the week spee spat it to the shirt, spat out to the terminal. 125 00:06:53,850 --> 00:06:57,240 I want you to have it saved in a file called today. 126 00:06:57,510 --> 00:07:00,420 TXT but also you still need to have the PT command in here. 127 00:07:00,420 --> 00:07:05,670 So I want you to press the upper arrow key to get what you've got before and now do the redirection. 128 00:07:06,060 --> 00:07:11,040 So I'm going to pull the video now and then come back and see how you did. 129 00:07:16,090 --> 00:07:16,840 How did you manage it? 130 00:07:16,840 --> 00:07:17,640 Did you do it? 131 00:07:17,650 --> 00:07:20,030 Well, this is how you this is how I'd go about it, right? 132 00:07:20,050 --> 00:07:26,230 So I would just right at the end here, because here's where the data is actually coming out from. 133 00:07:26,230 --> 00:07:32,280 I would just have a redirection from standard output into a file called today dot txt. 134 00:07:32,290 --> 00:07:35,110 And it's literally just that simple. 135 00:07:35,500 --> 00:07:42,430 So once we've done that, if I go ahead and press enter, we can see that when we open up our file commander 136 00:07:42,430 --> 00:07:42,760 here. 137 00:07:42,760 --> 00:07:49,180 We've now also got a file called today dot txt and inside there it has saved the data the day of the 138 00:07:49,180 --> 00:07:50,440 week, which in this case was Monday. 139 00:07:50,440 --> 00:07:53,170 Let me delete both files to so we can see this in all of its glory. 140 00:07:53,170 --> 00:07:54,250 We've got no files. 141 00:07:54,250 --> 00:07:56,680 I'm going to press the up arrow key press enter. 142 00:07:56,950 --> 00:07:58,630 And when we take a look ha ha. 143 00:07:58,630 --> 00:08:02,950 We've actually managed to save all the data into full data. 144 00:08:02,950 --> 00:08:08,410 TXT And we've also managed to save just what we wanted using redirection into today. 145 00:08:08,650 --> 00:08:10,390 TXT isn't that awesome? 146 00:08:10,390 --> 00:08:10,600 Right. 147 00:08:10,600 --> 00:08:12,730 That's kind of that's that's really awesome. 148 00:08:12,940 --> 00:08:13,570 I think so. 149 00:08:13,570 --> 00:08:19,420 Anyway, so what we've got here is the T command basically takes a snapshot of the data that's flowing 150 00:08:19,420 --> 00:08:26,380 through the pipe at that point and saves it in a file that, that you give it and then redirection will 151 00:08:26,380 --> 00:08:27,280 also do the same. 152 00:08:27,280 --> 00:08:31,630 But once you've redirected standard output, you can no longer pass it down the pipe. 153 00:08:31,870 --> 00:08:33,640 So that's why we use the PT command. 154 00:08:33,640 --> 00:08:38,710 The T command allows standard output to continue flowing down the pipe, but also allows you to effectively 155 00:08:38,710 --> 00:08:42,970 redirect it to a file and take a snapshot so that it's saved there. 156 00:08:43,299 --> 00:08:49,540 So another way of saying that is that once you've done redirection, you can't do any more piping. 157 00:08:49,780 --> 00:08:57,130 So once you've redirected standard output like we have here in the today txt, we can no longer do any 158 00:08:57,130 --> 00:08:59,470 more piping down down the pipeline. 159 00:08:59,470 --> 00:09:00,820 It's going to maximize the terminal. 160 00:09:01,420 --> 00:09:06,430 We can once we've done this redirection to today, that's the end of our piping days. 161 00:09:06,940 --> 00:09:13,180 But what we could do if we wanted to save all the data into the txt but continue the pipeline, then 162 00:09:13,180 --> 00:09:13,430 what? 163 00:09:13,480 --> 00:09:15,580 Then that's when the t command would come in. 164 00:09:15,820 --> 00:09:20,260 So we do for example today txt in the T command and now we can continue to pipe. 165 00:09:20,290 --> 00:09:20,660 Okay. 166 00:09:20,680 --> 00:09:26,470 So just again, if you do redirection of standard output, that means no more piping. 167 00:09:26,470 --> 00:09:32,290 If you want to take a snapshot, but continue piping, that's when you use the T command. 168 00:09:32,290 --> 00:09:34,660 And now I could continue piping on down. 169 00:09:34,660 --> 00:09:35,110 Okay. 170 00:09:35,110 --> 00:09:40,750 So I wanted to also cover the x args command in this video, but I think we're pushing it for time here. 171 00:09:40,750 --> 00:09:43,630 I hope that that has made it clear what the T command is. 172 00:09:43,630 --> 00:09:49,390 In final summary here, for the T command, the T command allows you to save a snapshot of the data 173 00:09:49,390 --> 00:09:55,720 and continue doing your piping, whereas just using redirection will save a snapshot of the data. 174 00:09:55,720 --> 00:09:57,670 But you can no longer do any piping. 175 00:09:57,670 --> 00:10:02,290 So if you want to keep building your pipeline but keep a snapshot of the data, use the T command instead. 176 00:10:02,290 --> 00:10:06,190 So in the next video, what we're going to do is we're going to have a look at the x args command, 177 00:10:06,190 --> 00:10:12,430 which is a really powerful command that allows you to turn your your pipe data into command line arguments. 178 00:10:12,430 --> 00:10:12,970 Ooh. 179 00:10:13,000 --> 00:10:13,300 Okay. 180 00:10:13,300 --> 00:10:16,270 So let's go ahead and I'll see you there in the next video.