WEBVTT 0 00:00.540 --> 00:04.980 So the first thing you're going to do is open up your Hyper Terminal. 1 00:04.980 --> 00:11.400 So the first thing that you might notice is that my preferences or my display or the skin on my terminal 2 00:11.400 --> 00:13.280 might look different from yours. 3 00:13.320 --> 00:15.480 Now I have it this green on black, 4 00:15.480 --> 00:21.180 just because I do a lot of development at night and it helps my eyes and it helps me going to sleep 5 00:21.240 --> 00:22.210 afterwards. 6 00:22.320 --> 00:28.170 And also there's the added benefit of when you're sitting in Starbucks and doing a lot of Bash scripting, 7 00:29.100 --> 00:34.470 people look at you really funny, like you're going to hack into their phone or something. 8 00:34.470 --> 00:39.570 And if you really want to take it to the extreme, and you've never seen this web site called hackertyper.com, 9 00:39.570 --> 00:45.990 you can actually pull it up on your browser and you can basically just bash the keys 10 00:46.710 --> 00:52.130 and you look like you're writing some insane piece of code. 11 00:52.170 --> 00:55.680 This is actually part of the Linux kernel, in case anybody's interested, 12 00:55.800 --> 01:03.200 and it's written in the C programming language, so that also is something that you can impress your friends. 13 01:03.210 --> 01:07.050 Now coming back to our actual lesson let's talk about the first command that we're going to learn today 14 01:07.260 --> 01:15.360 which is ls, which stands for list, and this lists all the items inside a particular directory. So you 15 01:15.360 --> 01:21.000 can see the location of where you are by whatever shows up after the colon. 16 01:21.000 --> 01:28.380 So at the moment this tilde shows me that I’m in my user directory. So that, in the Finder world, is basically 17 01:28.380 --> 01:29.120 here. 18 01:29.130 --> 01:32.240 So for example if we go back. 19 01:32.280 --> 01:38.110 So the root or the highest level in the hierarchy is your Macintosh HD. 20 01:38.610 --> 01:41.720 And then the next one is your Users folder. 21 01:41.820 --> 01:45.400 And on this computer my user name is angelayu. 22 01:45.420 --> 01:53.380 And when you see that tilde sign, you are at this level, you are inside this folder right now. 23 01:53.400 --> 02:00.000 So if I wanted to list all the items that are inside that folder then I simply write the ls command and 24 02:00.000 --> 02:00.920 hit enter. 25 02:00.930 --> 02:04.230 You can see it prints out all of the folders and files. 26 02:04.230 --> 02:10.740 So I've only got folders inside my root directory and you can see that it’s exactly the same as what you 27 02:10.740 --> 02:11.810 see in Finder. 28 02:11.820 --> 02:15.590 Now this is the location that you are taken to by default 29 02:15.600 --> 02:17.910 when you open up your terminal. 30 02:17.910 --> 02:19.260 This is the starting point. 31 02:19.260 --> 02:21.800 Now what if you don't want to be inside this folder? 32 02:21.810 --> 02:25.810 What if you want to navigate to a different directory, 33 02:25.920 --> 02:26.220 right? 34 02:26.220 --> 02:34.110 Say for example if I wanted to go into my Documents, and I want to go into Learn, and I've got this folder 35 02:34.110 --> 02:35.730 called Languages. 36 02:35.730 --> 02:41.490 And right now I'm learning German and the International Phonetic Alphabet in case anybody's interested. 37 02:41.490 --> 02:47.490 So how do I get myself from here all the way inside here? 38 02:47.490 --> 02:52.760 Well this is where the change directory, or the cd command, comes in handy. 39 02:53.280 --> 02:57.420 So we know that we are here right now because of the tilde sign. 40 02:57.630 --> 03:00.420 Let's navigate one level down. 41 03:00.420 --> 03:06.570 Let's go into our Documents folder. So I can simply write cd Documents. 42 03:06.600 --> 03:12.390 Now I can type out the entire thing myself but as a developer we're always looking for lazier ways of 43 03:12.390 --> 03:15.590 doing things and faster ways of doing things. 44 03:15.600 --> 03:22.620 So if you start typing Doc and you hit tab you can see that the terminal will auto fill the remainder 45 03:22.950 --> 03:24.360 of your folder name. 46 03:24.390 --> 03:27.540 Now you need enough letters for it to know what you're talking about. 47 03:27.630 --> 03:33.280 So for example if I just wrote Do, then it will tell me that there's Documents and Download. 48 03:33.360 --> 03:34.710 Which one do I want? 49 03:34.710 --> 03:41.980 So if I add a w and then I hit tab, then it knows that it can only be Downloads for example. 50 03:42.000 --> 03:42.240 Okay. 51 03:42.270 --> 03:48.530 So let's change directory to Documents, and you can see that the location has changed. 52 03:48.660 --> 03:53.280 This directory name after the colon is now saying Documents. 53 03:53.280 --> 03:59.030 So that means I am currently inside here. I am at this level. 54 03:59.490 --> 04:04.530 So if I wanted to go into this level, I would have to navigate into the Learn folder. 55 04:04.830 --> 04:07.970 So if you're following along, what would you type? 56 04:08.010 --> 04:09.430 Give it a go. 57 04:09.480 --> 04:16.410 Similar as what we did before we’re simply writing cd Learn and hit enter. 58 04:16.410 --> 04:23.130 So now we're inside Learn. Now it's a little bit tedious to navigate through directories one by one by 59 04:23.130 --> 04:23.550 one, 60 04:23.550 --> 04:23.850 right? 61 04:23.970 --> 04:29.880 So if we already knew that we want to go all the way into here then we can actually specify the entire 62 04:29.880 --> 04:31.380 path to get there. 63 04:31.740 --> 04:35.570 So for example right now I'm inside Learn. 64 04:35.810 --> 04:45.590 So let's go back to our root. So I can say cd tilde and hit enter and now I'm back at my root directory 65 04:45.770 --> 04:46.720 which is here. 66 04:47.180 --> 04:51.750 So let’s map out the path that I need in order to get to here. 67 04:51.890 --> 05:01.220 I need to go into Documents and then Learn and then Languages. So I can simply write cd Documents/Learn/ 68 05:03.290 --> 05:04.980 Languages/. 69 05:04.980 --> 05:11.450 And now if I hit enter I am inside Languages, which is over here. And that's a lot more succinct and a 70 05:11.450 --> 05:19.520 lot quicker than going through the directories one by one. Another really time saving feature of Terminal 71 05:19.700 --> 05:22.430 is the up and down buttons. 72 05:22.460 --> 05:27.080 So if you wanted to use the last command that you typed all you have to do is just hit the up button 73 05:27.440 --> 05:30.880 and you can see that I can use that change directory command again. 74 05:31.040 --> 05:34.180 But in my case I actually want to use the ls command. 75 05:34.340 --> 05:39.160 So obviously it's easier to simply type out ls rather than cycling through all those. 76 05:39.260 --> 05:44.180 But I just want to show you that you can actually go through your entire history of previous commands 77 05:44.540 --> 05:50.760 and you can then hit enter to execute it, and you can see that inside the Languages folder 78 05:50.870 --> 05:59.390 I have two other folders called German and IPA. So you can tell that we are at this level in our directory. 79 05:59.390 --> 06:05.460 Now sometimes typing out an entire path like this might seem like it's a lot of work. 80 06:05.510 --> 06:10.490 So I want to show you another neat trick that you can use when you have the Finder open and you just 81 06:10.490 --> 06:15.900 want to navigate to a deep directory without having to type out the entire path. 82 06:15.920 --> 06:16.770 So let's cd 83 06:16.770 --> 06:18.000 back to here, 84 06:18.050 --> 06:21.260 to our root directory for your user. 85 06:21.260 --> 06:24.250 So do you know how to do that? If you do, go ahead and do it now. 86 06:25.790 --> 06:28.790 So I'm going to cycle back and I found it. 87 06:28.790 --> 06:30.330 It's the cd tilde. 88 06:30.470 --> 06:35.630 And if I hit enter I am now back at my user’s root directory. 89 06:35.630 --> 06:41.180 Now once we're inside this Languages folder, how do we change directory back to the parent folders? 90 06:41.180 --> 06:44.500 How do we go backwards in this path? 91 06:44.540 --> 06:49.670 We're still going to be using the change directory or the cd command, and then after a space we're simply 92 06:49.670 --> 06:51.470 going to type two dots. 93 06:51.470 --> 06:54.260 And this takes us back one level, 94 06:54.290 --> 06:58.430 so from Languages I'm now in the Learn folder, 95 06:58.430 --> 07:05.030 so I'm now here. And I can keep doing this until I'm back at my root directory right here. 96 07:05.030 --> 07:10.080 So it took me three cd .. to get back to my roots. 97 07:10.190 --> 07:19.130 And the reason why you might want to do this is because, say if I was inside the Languages folder, so 98 07:19.160 --> 07:23.770 I'm now at the Languages directory, and I wanted to navigate 99 07:23.780 --> 07:32.390 now to my Music directory for example. I can't simply write cd Music. That’s not going to work because 100 07:32.450 --> 07:35.900 it's looking inside this Languages folder. 101 07:35.900 --> 07:38.040 It's looking to go forwards. 102 07:38.180 --> 07:44.480 So if I wanted to go backwards in the directory I either have to specify the entire file path, 103 07:44.480 --> 07:55.250 so that would be cd /, which is my Macintosh HD, Users/angelayu/Music. 104 07:55.250 --> 08:02.630 So I would have to specify the entire file path to go backwards and I can only specify just the name 105 08:02.630 --> 08:07.420 of the folder if I'm going forwards in terms of this hierarchy. 106 08:07.490 --> 08:15.110 Now what if I wanted to edit this at some point in the middle of this entire command? Because you can 107 08:15.110 --> 08:22.820 see that if I click at any of these places it doesn't really do what you expect it to do in a graphical 108 08:22.820 --> 08:23.910 user interface, right, 109 08:24.050 --> 08:31.280 namely allowing you to edit these parts. Your cursor is here and you can only type where your cursor 110 08:31.280 --> 08:39.290 is. So you can of course use the left arrow to go all the way back, but this is obviously very time consuming, 111 08:39.290 --> 08:41.530 especially if your command is very long. 112 08:41.600 --> 08:47.510 So a neat trick is holding down the option or the alt button and it gives you this little plus sign, 113 08:47.540 --> 08:55.000 and now you can click on one point in your command and you can now move the cursor to that position. 114 08:55.040 --> 08:57.080 So that's quite a neat trick as well. 115 08:57.170 --> 09:02.460 Now for people who have come from a long history of using graphical user interfaces such as you know 116 09:02.510 --> 09:11.990 your Mac OS or your Windows, having these little tricks like using the option click can be quite neat, 117 09:12.290 --> 09:21.680 but if you are a puritanical command line user then ideally you're aiming for never having to touch 118 09:21.680 --> 09:27.710 the mouse and you can do most things that you would want to do with the mouse very easily and quickly 119 09:28.070 --> 09:29.930 just using your keyboard. 120 09:29.930 --> 09:36.770 So for example if I wanted to go to the beginning of this line then I can simply hold down control and 121 09:36.770 --> 09:37.520 press A, 122 09:37.790 --> 09:44.570 so my cursor is now at the beginning. And if I hold down control and press E then I go to the end of my 123 09:44.570 --> 09:45.820 command line. 124 09:45.830 --> 09:50.840 Now you've already seen that I can cycle through my previous commands by using the up and down button. 125 09:51.170 --> 09:55.640 But what if I wanted to clear this current command without executing it? 126 09:55.730 --> 10:03.240 So to do that you can again hold down control and hit the U button, and that clears your entire line, 127 10:03.240 --> 10:05.450 so you can write a new command. 128 10:05.450 --> 10:11.150 So in the next lesson we're going to cover directories, making directories and secret folders. 129 10:11.210 --> 10:12.380 So I will see you there.