0 1 00:00:00,540 --> 00:00:04,980 So the first thing you're going to do is open up your Hyper Terminal. 1 2 00:00:04,980 --> 00: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 3 00:00:11,400 --> 00:00:13,280 might look different from yours. 3 4 00:00:13,320 --> 00:00:15,480 Now I have it this green on black, 4 5 00:00:15,480 --> 00: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 6 00:00:21,240 --> 00:00:22,210 afterwards. 6 7 00:00:22,320 --> 00: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 8 00:00:29,100 --> 00:00:34,470 people look at you really funny, like you're going to hack into their phone or something. 8 9 00:00:34,470 --> 00: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 10 00:00:39,570 --> 00:00:45,990 you can actually pull it up on your browser and you can basically just bash the keys 10 11 00:00:46,710 --> 00:00:52,130 and you look like you're writing some insane piece of code. 11 12 00:00:52,170 --> 00:00:55,680 This is actually part of the Linux kernel, in case anybody's interested, 12 13 00:00:55,800 --> 00:01:03,200 and it's written in the C programming language, so that also is something that you can impress your friends. 13 14 00:01:03,210 --> 00: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 15 00:01:07,260 --> 00:01:15,360 which is ls, which stands for list, and this lists all the items inside a particular directory. So you 15 16 00:01:15,360 --> 00:01:21,000 can see the location of where you are by whatever shows up after the colon. 16 17 00:01:21,000 --> 00: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 18 00:01:28,380 --> 00:01:29,120 here. 18 19 00:01:29,130 --> 00:01:32,240 So for example if we go back. 19 20 00:01:32,280 --> 00:01:38,110 So the root or the highest level in the hierarchy is your Macintosh HD. 20 21 00:01:38,610 --> 00:01:41,720 And then the next one is your Users folder. 21 22 00:01:41,820 --> 00:01:45,400 And on this computer my user name is angelayu. 22 23 00:01:45,420 --> 00:01:53,380 And when you see that tilde sign, you are at this level, you are inside this folder right now. 23 24 00:01:53,400 --> 00: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 25 00:02:00,000 --> 00:02:00,920 hit enter. 25 26 00:02:00,930 --> 00:02:04,230 You can see it prints out all of the folders and files. 26 27 00:02:04,230 --> 00: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 28 00:02:10,740 --> 00:02:11,810 see in Finder. 28 29 00:02:11,820 --> 00:02:15,590 Now this is the location that you are taken to by default 29 30 00:02:15,600 --> 00:02:17,910 when you open up your terminal. 30 31 00:02:17,910 --> 00:02:19,260 This is the starting point. 31 32 00:02:19,260 --> 00:02:21,800 Now what if you don't want to be inside this folder? 32 33 00:02:21,810 --> 00:02:25,810 What if you want to navigate to a different directory, 33 34 00:02:25,920 --> 00:02:26,220 right? 34 35 00:02:26,220 --> 00: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 36 00:02:34,110 --> 00:02:35,730 called Languages. 36 37 00:02:35,730 --> 00:02:41,490 And right now I'm learning German and the International Phonetic Alphabet in case anybody's interested. 37 38 00:02:41,490 --> 00:02:47,490 So how do I get myself from here all the way inside here? 38 39 00:02:47,490 --> 00:02:52,760 Well this is where the change directory, or the cd command, comes in handy. 39 40 00:02:53,280 --> 00:02:57,420 So we know that we are here right now because of the tilde sign. 40 41 00:02:57,630 --> 00:03:00,420 Let's navigate one level down. 41 42 00:03:00,420 --> 00:03:06,570 Let's go into our Documents folder. So I can simply write cd Documents. 42 43 00:03:06,600 --> 00: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 44 00:03:12,390 --> 00:03:15,590 doing things and faster ways of doing things. 44 45 00:03:15,600 --> 00: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 46 00:03:22,950 --> 00:03:24,360 of your folder name. 46 47 00:03:24,390 --> 00:03:27,540 Now you need enough letters for it to know what you're talking about. 47 48 00:03:27,630 --> 00:03:33,280 So for example if I just wrote Do, then it will tell me that there's Documents and Download. 48 49 00:03:33,360 --> 00:03:34,710 Which one do I want? 49 50 00:03:34,710 --> 00: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 51 00:03:42,000 --> 00:03:42,240 Okay. 51 52 00:03:42,270 --> 00:03:48,530 So let's change directory to Documents, and you can see that the location has changed. 52 53 00:03:48,660 --> 00:03:53,280 This directory name after the colon is now saying Documents. 53 54 00:03:53,280 --> 00:03:59,030 So that means I am currently inside here. I am at this level. 54 55 00:03:59,490 --> 00:04:04,530 So if I wanted to go into this level, I would have to navigate into the Learn folder. 55 56 00:04:04,830 --> 00:04:07,970 So if you're following along, what would you type? 56 57 00:04:08,010 --> 00:04:09,430 Give it a go. 57 58 00:04:09,480 --> 00:04:16,410 Similar as what we did before we’re simply writing cd Learn and hit enter. 58 59 00:04:16,410 --> 00: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 60 00:04:23,130 --> 00:04:23,550 one, 60 61 00:04:23,550 --> 00:04:23,850 right? 61 62 00:04:23,970 --> 00: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 63 00:04:29,880 --> 00:04:31,380 path to get there. 63 64 00:04:31,740 --> 00:04:35,570 So for example right now I'm inside Learn. 64 65 00:04:35,810 --> 00: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 66 00:04:45,770 --> 00:04:46,720 which is here. 66 67 00:04:47,180 --> 00:04:51,750 So let’s map out the path that I need in order to get to here. 67 68 00:04:51,890 --> 00:05:01,220 I need to go into Documents and then Learn and then Languages. So I can simply write cd Documents/Learn/ 68 69 00:05:03,290 --> 00:05:04,980 Languages/. 69 70 00:05:04,980 --> 00: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 71 00:05:11,450 --> 00:05:19,520 lot quicker than going through the directories one by one. Another really time saving feature of Terminal 71 72 00:05:19,700 --> 00:05:22,430 is the up and down buttons. 72 73 00:05:22,460 --> 00: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 74 00:05:27,440 --> 00:05:30,880 and you can see that I can use that change directory command again. 74 75 00:05:31,040 --> 00:05:34,180 But in my case I actually want to use the ls command. 75 76 00:05:34,340 --> 00:05:39,160 So obviously it's easier to simply type out ls rather than cycling through all those. 76 77 00:05:39,260 --> 00:05:44,180 But I just want to show you that you can actually go through your entire history of previous commands 77 78 00:05:44,540 --> 00:05:50,760 and you can then hit enter to execute it, and you can see that inside the Languages folder 78 79 00:05:50,870 --> 00: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 80 00:05:59,390 --> 00:06:05,460 Now sometimes typing out an entire path like this might seem like it's a lot of work. 80 81 00:06:05,510 --> 00: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 82 00:06:10,490 --> 00:06:15,900 want to navigate to a deep directory without having to type out the entire path. 82 83 00:06:15,920 --> 00:06:16,770 So let's cd 83 84 00:06:16,770 --> 00:06:18,000 back to here, 84 85 00:06:18,050 --> 00:06:21,260 to our root directory for your user. 85 86 00:06:21,260 --> 00:06:24,250 So do you know how to do that? If you do, go ahead and do it now. 86 87 00:06:25,790 --> 00:06:28,790 So I'm going to cycle back and I found it. 87 88 00:06:28,790 --> 00:06:30,330 It's the cd tilde. 88 89 00:06:30,470 --> 00:06:35,630 And if I hit enter I am now back at my user’s root directory. 89 90 00:06:35,630 --> 00:06:41,180 Now once we're inside this Languages folder, how do we change directory back to the parent folders? 90 91 00:06:41,180 --> 00:06:44,500 How do we go backwards in this path? 91 92 00:06:44,540 --> 00: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 93 00:06:49,670 --> 00:06:51,470 going to type two dots. 93 94 00:06:51,470 --> 00:06:54,260 And this takes us back one level, 94 95 00:06:54,290 --> 00:06:58,430 so from Languages I'm now in the Learn folder, 95 96 00:06:58,430 --> 00: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 97 00:07:05,030 --> 00:07:10,080 So it took me three cd .. to get back to my roots. 97 98 00:07:10,190 --> 00: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 99 00:07:19,160 --> 00:07:23,770 I'm now at the Languages directory, and I wanted to navigate 99 100 00:07:23,780 --> 00: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 101 00:07:32,450 --> 00:07:35,900 it's looking inside this Languages folder. 101 102 00:07:35,900 --> 00:07:38,040 It's looking to go forwards. 102 103 00:07:38,180 --> 00:07:44,480 So if I wanted to go backwards in the directory I either have to specify the entire file path, 103 104 00:07:44,480 --> 00:07:55,250 so that would be cd /, which is my Macintosh HD, Users/angelayu/Music. 104 105 00:07:55,250 --> 00: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 106 00:08:02,630 --> 00:08:07,420 of the folder if I'm going forwards in terms of this hierarchy. 106 107 00:08:07,490 --> 00: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 108 00:08:15,110 --> 00: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 109 00:08:22,820 --> 00:08:23,910 user interface, right, 109 110 00:08:24,050 --> 00:08:31,280 namely allowing you to edit these parts. Your cursor is here and you can only type where your cursor 110 111 00:08:31,280 --> 00: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 112 00:08:39,290 --> 00:08:41,530 especially if your command is very long. 112 113 00:08:41,600 --> 00: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 114 00:08:47,540 --> 00: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 115 00:08:55,040 --> 00:08:57,080 So that's quite a neat trick as well. 115 116 00:08:57,170 --> 00:09:02,460 Now for people who have come from a long history of using graphical user interfaces such as you know 116 117 00:09:02,510 --> 00:09:11,990 your Mac OS or your Windows, having these little tricks like using the option click can be quite neat, 117 118 00:09:12,290 --> 00:09:21,680 but if you are a puritanical command line user then ideally you're aiming for never having to touch 118 119 00:09:21,680 --> 00: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 120 00:09:28,070 --> 00:09:29,930 just using your keyboard. 120 121 00:09:29,930 --> 00: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 122 00:09:36,770 --> 00:09:37,520 press A, 122 123 00:09:37,790 --> 00: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 124 00:09:44,570 --> 00:09:45,820 command line. 124 125 00:09:45,830 --> 00:09:50,840 Now you've already seen that I can cycle through my previous commands by using the up and down button. 125 126 00:09:51,170 --> 00:09:55,640 But what if I wanted to clear this current command without executing it? 126 127 00:09:55,730 --> 00: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 128 00:10:03,240 --> 00:10:05,450 so you can write a new command. 128 129 00:10:05,450 --> 00:10:11,150 So in the next lesson we're going to cover directories, making directories and secret folders. 129 130 00:10:11,210 --> 00:10:12,380 So I will see you there.