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