0 1 00:00:00,870 --> 00:00:06,690 So the first thing that we're going to do is to open up Terminals. So if you don't remember how to do 1 2 00:00:06,690 --> 00:00:12,840 that, just simply go to Spotlight Search, so you can click it over here, or you can simply hit the command 2 3 00:00:12,840 --> 00:00:13,580 space bar. 3 4 00:00:14,220 --> 00:00:17,850 That's the default setting for bringing up Spotlight. 4 5 00:00:17,850 --> 00:00:22,320 Alternatively, you can just go into your Applications folder and you'll be fine there as well. But in 5 6 00:00:22,320 --> 00:00:24,250 Spotlight, I'm going to search for Terminal. 6 7 00:00:24,300 --> 00:00:32,420 And here is my brand-new Bash Shell and you can see it is a Bash Shell because it tells you so uphill. 7 8 00:00:32,730 --> 00:00:39,150 So the first thing that you might notice is that my preferences or my display or the skin on my Terminal 8 9 00:00:39,150 --> 00:00:41,080 might look different from yours. 9 10 00:00:41,100 --> 00:00:47,610 So if you want to change it to whatever you like, then you can simply head over to preferences and change 10 11 00:00:47,610 --> 00:00:49,290 it inside profiles. 11 12 00:00:49,290 --> 00:00:55,020 Now, I have it this green on black just because I do a lot of development at night and it helps my eyes 12 13 00:00:55,410 --> 00:00:58,240 and it helps me going to sleep afterwards. 13 14 00:00:58,260 --> 00:01:04,140 And also there's the added benefit of when you're sitting in Starbucks and doing a lot of bash scripting, 14 15 00:01:05,070 --> 00:01:10,140 people look at you really funny, like you're going to hack into their phone or something. 15 16 00:01:10,410 --> 00:01:15,510 And if you really want to take it to the extreme and you've never seen this website called hackertyper.com, 16 17 00:01:15,510 --> 00:01:21,930 and you can actually pull it up on your browser and you can basically just bash the keys, 17 18 00:01:22,650 --> 00:01:28,090 and you look like you're writing some insane piece of code, 18 19 00:01:28,110 --> 00:01:33,870 this is actually part of the Linux kernel, in case anybody's interested, and it's written in the C programming 19 20 00:01:33,870 --> 00:01:34,710 language. 20 21 00:01:34,710 --> 00:01:39,160 So that, also, is something that you can impress your friends. 21 22 00:01:39,180 --> 00:01:42,990 Now, going back to our actual lesson, let's talk about the first command that we're going to learn today 22 23 00:01:43,230 --> 00:01:50,890 which is "ls" which stands for list. And this lists all the items inside a particular directory. 23 24 00:01:50,910 --> 00:01:56,940 So you can see the location of where you are by whatever shows up after the colon. 24 25 00:01:56,940 --> 00:02:04,350 So at the moment, this tilde shows me that I might use a directory so that in the Finder world is basically 25 26 00:02:04,350 --> 00:02:04,880 here. 26 27 00:02:05,100 --> 00:02:08,190 So, for example, if we go back. 27 28 00:02:08,220 --> 00:02:16,020 So the root or the highest level in the hierarchy is your Macintosh harddrive, and then the next one 28 29 00:02:16,080 --> 00:02:17,720 is your Users folder. 29 30 00:02:17,790 --> 00:02:25,140 And on this computer, my user name is angelayu. And when you see that tilde sign, you are at this 30 31 00:02:25,140 --> 00:02:29,230 level. You are inside this folder right now. 31 32 00:02:29,370 --> 00:02:35,730 So if I wanted to list all the items that are inside that folder, then I simply write the "ls" command 32 33 00:02:35,790 --> 00:02:36,870 and hit enter. 33 34 00:02:36,870 --> 00:02:40,160 You can see it prints out all of the folders and files. 34 35 00:02:40,170 --> 00:02:43,980 So I've only got folders inside my root directory 35 36 00:02:44,010 --> 00:02:47,730 and you can see that it's exactly the same as what you see in Finder. 36 37 00:02:47,760 --> 00:02:53,880 Now, this is the location that you are taken to by default when you open up your Terminal. 37 38 00:02:53,880 --> 00:02:55,230 This is the starting point. 38 39 00:02:55,230 --> 00:02:57,750 Now, what if you don't want to be inside this folder? 39 40 00:02:57,750 --> 00:03:01,850 What if you want to navigate to a different directory, 40 41 00:03:01,890 --> 00:03:02,160 right? 41 42 00:03:02,160 --> 00:03:10,080 Say, for example, if I wanted to go into my Documents and I want to go in to Learn, and I've got this folder 42 43 00:03:10,080 --> 00:03:11,550 called Languages. 43 44 00:03:11,760 --> 00:03:17,230 And right now, I'm learning German and the International Phonetic Alphabet in case anybody is interested. 44 45 00:03:17,460 --> 00:03:22,930 So how do I get myself from here all the way inside here? 45 46 00:03:23,400 --> 00:03:28,980 Well, this is where the change directory or the cd command comes in handy. 46 47 00:03:29,220 --> 00:03:33,420 So we know that we are here right now because of the tilde sign. 47 48 00:03:33,600 --> 00:03:36,380 Let's navigate one level down. 48 49 00:03:36,390 --> 00:03:42,540 Let's go into our Documents folder. so I can simply write cd Documents. 49 50 00:03:42,570 --> 00:03:48,360 Now, I can type out the entire thing myself. But as a developer, we're always looking for lazy ways of 50 51 00:03:48,360 --> 00:03:51,420 doing things and faster ways of doing things. 51 52 00:03:51,540 --> 00:03:58,590 So, if you start typing doc and you hit tab, you can see that the Terminal will autofill the remainder 52 53 00:03:58,890 --> 00:04:00,420 of your folder name. 53 54 00:04:00,420 --> 00:04:03,570 Now, you need enough letters for it to know what you're talking about. 54 55 00:04:03,570 --> 00:04:09,170 So, for example, if I just wrote "Do," then it will tell me that these documents and downloads 55 56 00:04:09,330 --> 00:04:10,490 which one do I want. 56 57 00:04:10,560 --> 00:04:18,970 So if I add a "w" and then I hit tab, then it knows that it can only be "downloads," for example. 57 58 00:04:19,350 --> 00:04:19,620 Okay. 58 59 00:04:19,620 --> 00:04:26,880 So let's change directory to Documents and you can see that the location has changed this directory 59 60 00:04:26,880 --> 00:04:30,620 name after the colon is now saying "Documents." 60 61 00:04:30,630 --> 00:04:36,840 So that means, I am currently inside here, I am at this level. 61 62 00:04:36,840 --> 00:04:42,050 So if I wanted to go into this level, I would have to navigate into the Learn folder. 62 63 00:04:42,210 --> 00:04:45,250 So if you're following along, what would you type? 63 64 00:04:45,350 --> 00:04:46,170 Give it a go. 64 65 00:04:46,850 --> 00:04:53,660 Similar as what we did before, we simply writing "cd learn" and hit enter. 65 66 00:04:53,780 --> 00:04:55,390 So now we're inside learn. 66 67 00:04:55,610 --> 00:05:00,920 Now, it's a little bit tedious to navigate through directories one by one by one, 67 68 00:05:00,920 --> 00:05:01,310 right? 68 69 00:05:01,340 --> 00:05:07,220 So if we already knew that we want to go all the way into here, then we can actually specify the entire 69 70 00:05:07,220 --> 00:05:08,910 path to get there. 70 71 00:05:09,080 --> 00:05:13,160 So, for example, right now I'm inside Learn. 71 72 00:05:13,160 --> 00:05:23,000 So let's go back to our roots. So I can say cd ~ and hit enter, and now I'm back at my root directory 72 73 00:05:23,120 --> 00:05:24,200 which is here. 73 74 00:05:24,560 --> 00:05:29,050 So let's map out the path that I need in order to get to here. 74 75 00:05:29,240 --> 00:05:33,060 I need to go into Documents, and then Learn, and then Languages. 75 76 00:05:33,320 --> 00:05:42,030 So I can simply write cd Documents/Learn/Languages. 76 77 00:05:42,350 --> 00:05:48,830 And now if I hit enter, I am inside Languages, which is over here, and that's a lot more succinct and a 77 78 00:05:48,830 --> 00:05:53,680 lot quicker than going through the directories one by one. 78 79 00:05:53,870 --> 00:05:59,700 Another really timesaving feature of Terminal is the up and down buttons. 79 80 00:05:59,810 --> 00:06:04,430 So if you wanted to use the last command that you typed, all you have to do is just hit the up button, 80 81 00:06:04,790 --> 00:06:08,180 and you can see that I can use that change directory command again. 81 82 00:06:08,420 --> 00:06:11,580 But in my case, I actually want to use the "ls" command. 82 83 00:06:11,690 --> 00:06:16,440 So obviously, it's easier to simply type out "ls," rather than cycling through all those. 83 84 00:06:16,610 --> 00:06:21,530 But I just want to show you that you can actually go through your entire history of previous commands 84 85 00:06:21,920 --> 00:06:27,990 and you can then hit enter to execute it. And you can see that inside the Languages folder, 85 86 00:06:28,220 --> 00:06:31,330 I have two other folders called German and IPA. 86 87 00:06:31,430 --> 00:06:37,190 So you can tell that we are at this level in our directory. 87 88 00:06:37,220 --> 00:06:42,850 Now, sometimes typing out an entire path like this might seem like it's a lot of work. 88 89 00:06:42,890 --> 00:06:47,870 So I want to show you another neat trick that you can use when you have the Finder open and you just 89 90 00:06:47,870 --> 00:06:53,150 want to navigate to a deep directory without having to type out the entire path. 90 91 00:06:53,270 --> 00:06:58,150 So let's see back to here, to our root directory for your user. 91 92 00:06:58,580 --> 00:06:59,820 So do you remember how to do that? 92 93 00:06:59,900 --> 00:07:01,910 If you do, go ahead and do it now. 93 94 00:07:03,140 --> 00:07:06,080 So I'm going to cycle back and I found it, 94 95 00:07:06,140 --> 00:07:07,460 it's the cd ~ 95 96 00:07:07,820 --> 00:07:12,810 and if I hit enter, I am now back at my user's root directory. 96 97 00:07:13,100 --> 00:07:18,710 So, now I want to show you a different way of getting to Languages without having to type out the entire 97 98 00:07:18,740 --> 00:07:19,370 path. 98 99 00:07:19,370 --> 00:07:26,750 So the way to do that is simply to write cd space, and then all I'm going to do is just click and drag 99 100 00:07:26,750 --> 00:07:35,260 this directory into the Terminal, and you can see that it prints the entire path to this folder. 100 101 00:07:35,420 --> 00:07:42,200 So if I now hit enter, then I am again inside this Languages folder over here, and that might in some 101 102 00:07:42,200 --> 00:07:46,750 cases, be a faster way for you to navigate in your directories. 102 103 00:07:46,760 --> 00:07:52,310 Now, once we're inside this Languages folder, how do we change our directory back to the parent folders? 103 104 00:07:52,310 --> 00:07:55,630 How do we go backwards in this path? 104 105 00:07:55,670 --> 00:08:00,830 We're still going to be using the change directory or the cd command. And then after a space, we simply 105 106 00:08:00,980 --> 00:08:05,390 type two dots, and this takes us back one level. 106 107 00:08:05,390 --> 00:08:13,550 So from Languages, I'm now in the Learn folders, I'm now here. And I can keep doing this until I'm back 107 108 00:08:13,610 --> 00:08:15,990 at my root directory right here. 108 109 00:08:16,160 --> 00:08:21,160 So it took me three "cd .." to get back to my roots. 109 110 00:08:21,320 --> 00:08:29,600 And the reason why you might want to do this is because, say, if I was inside the Languages folder, 110 111 00:08:30,050 --> 00:08:38,870 so I'm now at the Languages directory, and I wanted to navigate now to my Music directory, for example. 111 112 00:08:38,870 --> 00:08:42,170 I can't simply write cd Music, 112 113 00:08:42,170 --> 00:08:47,030 that's not going to work because it's looking inside this Languages folder. 113 114 00:08:47,030 --> 00:08:49,270 It's looking to go forwards. 114 115 00:08:49,310 --> 00:08:55,940 So if I wanted to go backwards in the directory, I either have to specify the entire file path, so that 115 116 00:08:55,940 --> 00:09:07,070 would be cd / which is my Macintosh hard drive, Users/angelayu/Music. So I would have to 116 117 00:09:07,070 --> 00:09:14,430 specify the entire file path to go backwards. And I can only specify just the name of the folder. 117 118 00:09:14,510 --> 00:09:21,560 If I'm going forwards in terms of this hierarchy. So another thing that's really useful is that sometimes 118 119 00:09:21,650 --> 00:09:29,390 your screen will get clogged up with loads of commands. And you can simply write the command clear to 119 120 00:09:29,390 --> 00:09:30,870 clear your entire screen. 120 121 00:09:30,980 --> 00:09:37,970 So right now, I'm still inside the Music folder. But instead, I want to be inside root. So the next 121 122 00:09:37,970 --> 00:09:43,070 thing I want to show you is that if you've been used to a graphical user interface, and this is something that 122 123 00:09:43,490 --> 00:09:45,610 people tend to request. 123 124 00:09:45,620 --> 00:09:52,650 So, for example, let's say we're going to use the cd command again and we're going to go into Languages. 124 125 00:09:53,300 --> 00:10:00,260 Now, what if I wanted to edit this at some point in the middle of this entire command? 125 126 00:10:00,410 --> 00:10:06,710 Because you can see that if I click at any of these places, it doesn't really do what you expected to 126 127 00:10:06,710 --> 00:10:09,750 do in a graphical user interface, right? 127 128 00:10:09,860 --> 00:10:13,300 Namely allowing you to edit these parts. 128 129 00:10:13,820 --> 00:10:17,570 Your cursor is here and you can only type where your cursor is. 129 130 00:10:17,720 --> 00:10:25,070 So you can, of course, use the left arrow to go all the way back, but this is, obviously, very time consuming, 130 131 00:10:25,070 --> 00:10:30,950 especially if your command is very long. So a neat trick is holding down the option or the alt button 131 132 00:10:31,340 --> 00:10:38,030 and it gives you this little plus sign, and now you can click on one point in your command and you can 132 133 00:10:38,030 --> 00:10:40,630 now move the cursor to that position. 133 134 00:10:40,820 --> 00:10:42,940 So that's quite a neat trick as well. 134 135 00:10:42,980 --> 00:10:48,290 Now, for people who have come from a long history of using graphical user interfaces, such as, you know, 135 136 00:10:48,290 --> 00:10:56,420 your macOS or your Windows, having these little tricks like the cd, and then dragging in the folder, or 136 137 00:10:56,420 --> 00:11:07,970 using the option click, can be quite neat, but if you are a puritanical command-line user, then ideally, 137 138 00:11:08,060 --> 00:11:13,730 you're aiming for never having to touch the mouse. And you can do most things that you would want to 138 139 00:11:13,730 --> 00:11:18,690 do with the mouse very easily and quickly just using your keyboard. 139 140 00:11:18,800 --> 00:11:25,640 So, for example, if I wanted to go to the beginning of this line, then I can simply hold down control and 140 141 00:11:25,640 --> 00:11:26,530 press A, 141 142 00:11:26,660 --> 00:11:33,410 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 142 143 00:11:33,410 --> 00:11:34,700 command line. 143 144 00:11:34,700 --> 00:11:39,850 Now, you've already seen that I can cycle through my previous commands by using the up and down button. 144 145 00:11:40,040 --> 00:11:44,390 But what if I wanted to clear this current command without executing it? 145 146 00:11:44,600 --> 00:11:51,820 So to do that, you can, again, hold down control and hit the U button, and that clears your entire line. 146 147 00:11:52,020 --> 00:11:53,850 So you can write a new command. 147 148 00:11:53,990 --> 00:11:59,790 So I've only shown you some of the most common shortcuts that I use on a day-to-day basis, 148 149 00:12:00,080 --> 00:12:07,370 but I'm just scratching surface here. There's so many really useful shortcuts that you can tap into and 149 150 00:12:07,430 --> 00:12:13,940 I'll link you to a resource that I like to use which is a Terminal Mac Cheat sheet and it's hosted on GitHub, 150 151 00:12:13,970 --> 00:12:20,660 so you can have a look at it. And there's Polish, Portuguese, Vietnamese versions of it that you can read. 151 152 00:12:20,720 --> 00:12:22,580 And it's got a lot more shortcuts. 152 153 00:12:22,670 --> 00:12:27,640 So, obviously, if you're new to the command line, then it might be a good idea to integrate these, 153 154 00:12:27,740 --> 00:12:29,360 you know, only a few at a time, 154 155 00:12:29,380 --> 00:12:34,580 because you can't learn all of these shortcuts in one day and it can be quite overwhelming to do that. 155 156 00:12:34,670 --> 00:12:40,610 But this is a good reference if you want to look at more things that you can do quickly inside the command 156 157 00:12:40,610 --> 00:12:44,360 line just by using your keyboard. 157 158 00:12:44,360 --> 00:12:50,010 So in the next lesson, we're going to cover directories, making directories, and secret folders. 158 159 00:12:50,120 --> 00:12:51,340 So I'll see you there.