1 00:00:00,000 --> 00:00:01,828 [No audio] 2 00:00:01,828 --> 00:00:06,419 Pipes. A pipe is used by the shell to connect the 3 00:00:06,419 --> 00:00:09,958 output of one command directly to the input of 4 00:00:09,958 --> 00:00:13,649 another command. The symbol for a pipe is the 5 00:00:13,649 --> 00:00:19,679 vertical bar, the command syntax is command, or 6 00:00:19,679 --> 00:00:22,679 the option or the argument, and then you pipe it, 7 00:00:22,979 --> 00:00:25,499 to another command, whether it's option on 8 00:00:25,499 --> 00:00:29,878 argument if there is any. Basically, if you want 9 00:00:29,878 --> 00:00:32,668 to connect two commands together, or if you want 10 00:00:32,668 --> 00:00:36,058 to take the output of the first command, and pipe 11 00:00:36,058 --> 00:00:39,808 it to a different output, then you could use a 12 00:00:39,808 --> 00:00:45,479 pipe. In a Mac keyboard, a pipe is somewhere the 13 00:00:45,479 --> 00:00:47,308 key all the way to the right, that looks like 14 00:00:47,308 --> 00:00:51,298 that. And in a regular keyboard, you will see the 15 00:00:51,298 --> 00:00:56,008 pipe option is right below the backspace. And you 16 00:00:56,008 --> 00:01:01,258 could do I think, with the shift and pipe. So the 17 00:01:01,258 --> 00:01:05,158 way it works is you have a, you have a command, it 18 00:01:05,158 --> 00:01:10,198 goes into a pipe, and it comes out the output. So 19 00:01:10,198 --> 00:01:12,509 let's say if you have ls -l, that's a command 20 00:01:12,509 --> 00:01:16,768 you run, you pipe that, the exact same pipe 21 00:01:17,278 --> 00:01:20,158 character that you use, and you put another 22 00:01:20,158 --> 00:01:25,109 command to it to refine the output of your last 23 00:01:25,109 --> 00:01:29,579 command. So let's look at the example in our Linux machine. 24 00:01:29,579 --> 00:01:35,010 [No audio] 25 00:01:35,010 --> 00:01:40,139 If we are in slash etc directory, by the way, 26 00:01:40,139 --> 00:01:42,629 where we are? We are in our home directory. So if 27 00:01:42,629 --> 00:01:47,699 he if we go into cd /etc, now this 28 00:01:47,699 --> 00:01:51,959 directory has a bunch of files and directories, 29 00:01:52,290 --> 00:01:55,650 which you can now view all in one page, it will 30 00:01:55,860 --> 00:01:59,400 display all at once. But everything will scroll up 31 00:01:59,400 --> 00:02:02,160 so fast that you wouldn't even able to view one by 32 00:02:02,160 --> 00:02:05,580 one. So when you do ls -ltr, you hit enter. 33 00:02:06,239 --> 00:02:09,630 You see, it went up so fast. What you could do, 34 00:02:09,630 --> 00:02:12,600 you could scroll up, of course, when you do, 35 00:02:13,679 --> 00:02:16,380 scroll down slow by slow, you're gonna see all 36 00:02:16,380 --> 00:02:21,449 those files, commands and directories that are 37 00:02:21,479 --> 00:02:27,089 inside of etc. Now you want to view all of them 38 00:02:27,330 --> 00:02:32,039 one page at a time. So how do you do that? The way 39 00:02:32,039 --> 00:02:34,860 you do it, you put it in a pipe. So first you 40 00:02:34,860 --> 00:02:39,600 do ls -ltr, you pipe it, and then, there's a 41 00:02:39,600 --> 00:02:42,210 new command that I want you to learn which is 42 00:02:42,210 --> 00:02:46,589 called more. more is the command which gives you 43 00:02:46,889 --> 00:02:51,449 the output of a file one page at a time. So when 44 00:02:51,449 --> 00:02:54,839 you do ls -ltr, pipe it, and more it, hit enter, 45 00:02:54,869 --> 00:02:58,619 so now you will see one page at a time of all the 46 00:02:58,619 --> 00:03:01,529 contents of etc directory, and at the bottom, it 47 00:03:01,529 --> 00:03:06,690 does tell you that it's more. You hit spacebar to 48 00:03:06,690 --> 00:03:10,350 go down to the second page, spacebar again, 49 00:03:10,649 --> 00:03:13,979 spacebar again, wherever you are, you could quit 50 00:03:13,979 --> 00:03:16,649 out of it by hitting Q, and you will get your 51 00:03:16,649 --> 00:03:20,520 prompt back. Again, let's do up arrow key. Hit 52 00:03:20,520 --> 00:03:24,630 enter, spacebar, spacebar, spacebar, spacebar to 53 00:03:24,630 --> 00:03:26,850 go all the way down, you will keep hitting the 54 00:03:26,850 --> 00:03:29,580 spacebar and get your prompt back. So that's how 55 00:03:29,580 --> 00:03:34,020 you put in a pipe. You could also do a pipe to 56 00:03:34,020 --> 00:03:38,190 have the output of a command and change its output 57 00:03:38,190 --> 00:03:41,639 to a different way. Let's say if you want to do 58 00:03:41,699 --> 00:03:45,630 ls, by the way, there's another command which is a 59 00:03:45,630 --> 00:03:48,509 simple command if you want it to learn is ll, 60 00:03:48,570 --> 00:03:50,550 which also gives you the result as if you are 61 00:03:50,550 --> 00:03:56,580 doing ls -l. So you do ll, and you'd learn the 62 00:03:56,580 --> 00:03:59,729 command more, which gives you one page at a time. 63 00:04:00,539 --> 00:04:04,979 What if you want to get the last line of your 64 00:04:04,979 --> 00:04:09,750 output, then you run ls -l, pipe it, and to get 65 00:04:09,750 --> 00:04:14,009 the last line you will have to do tail -1. 66 00:04:15,089 --> 00:04:19,920 It gives you the last line of your output. Now 67 00:04:19,920 --> 00:04:24,480 tail is another command which is also a cool 68 00:04:24,480 --> 00:04:28,589 command which will give you the last line or lines 69 00:04:28,980 --> 00:04:33,239 of an output, which we'll cover later on. So this 70 00:04:33,239 --> 00:04:35,429 is what the pipe is. I want you to try with 71 00:04:35,429 --> 00:04:39,899 different commands, learn about pipe. I'm not sure 72 00:04:39,899 --> 00:04:43,769 if there is a man page for pipe because it's a 73 00:04:43,769 --> 00:04:48,119 character, but let's see. Yeah, there is none. But 74 00:04:48,119 --> 00:04:51,089 if you wanted to know more about pipe, I have some 75 00:04:51,089 --> 00:04:53,910 documentation you could get it or you could of 76 00:04:53,910 --> 00:04:56,640 course go look it up online to find out more about 77 00:04:56,640 --> 00:05:00,209 pipes. The pipe is is very important for all are 78 00:05:00,209 --> 00:05:03,899 lessons that we will be covering later on because 79 00:05:03,899 --> 00:05:07,079 this is how we're going to combine our commands. 80 00:05:07,079 --> 00:05:09,503 [No audio]