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