The first thing you're going to do is open up your terminal.
So the first thing that you might notice is that my preferences or my display or the skin on my terminal
might look different from yours.
Now I have it, this green on black
just because I do a lot of development at night and it helps my eyes and it helps me going to sleep
afterwards.
And also there's the added benefit of when you're sitting in Starbucks and doing a lot of bash scripting,
people look at you really funny, like you're going to hack into their phone or something.
And if you really want to take it to the extreme and you've never seen this website called hackertyper.com,
and you can actually pull it up on your browser and you can basically just bash the keys and you look
like you're writing some insane piece of code.
This is actually part of the Linux kernel in case anybody's interested
and it's written in the C programming language.
So that also is something that you can impress your friends.
Now, coming back to our actual lesson, let's talk about the first command that we're going to learn
today, which is "ls", which stands for list.
And this lists all the items inside a particular directory.
So you can see the location of where you are by whatever shows up here.
So at the moment, this tilde shows me that I'm in my user directory, so that in the Finder world is
basically here.
So the root or the highest level in the hierarchy is your Macintosh hard drive,
and then the next one is your users folder
and on this computer my username is Angela Yu.
And when you see that tilde sign, you are at this level.
You are inside this folder right now.
If I wanted to list all the items that are inside that folder, then I simply write the ls command and
hit Enter.
You can see it prints out all of the folders and files,
so I've only got folders inside my root directory and you can see that it's exactly the same as what
you see in Finder.
Now what if you don't want to be inside this folder?
What if you want to navigate to a different directory, right?
Say, for example, if I wanted to go into My Documents and I want to go into Learn and I've got this
folder called Languages, and right now I'm learning German and the International Phonetic Alphabet in
case anybody's interested.
So how do I get myself from here all the way inside here?
Well, this is where the change directory or the "cd" command comes in handy.
We know that we are here right now because of the tilde sign.
Let's navigate one level down.
Let's go into our Documents folder, so I can simply write, "cd Documents".
Now I can type out the entire thing myself,
but as a developer, we're always looking for lazier ways of doing things and faster ways of doing things.
So if you start typing Doc and you hit Tab, you can see that the terminal will auto-fill the remainder
of your folder name.
Now you need enough letters for it to know what you're talking about.
So for example, if I just wrote Do then it will tell me that there's Documents and Downloads,
which one do I want?
So if I add a w and then I hit Tab, then it knows that it can only be Downloads, for example.
Okay, so let's change the directory to Documents and you can see that the location has changed,
this directory name is now saying Documents.
So that means I am currently inside here. I am at this level.
So if I wanted to go into this level, I would have to navigate into the Learn folder.
So if you're following along, what would you type?
Give it a go.
Similar as what we did before,
we're simply writing "cd Learn" and hit Enter.
So now we're inside Learn.
Now it's a little bit tedious to navigate through directories one by one by one, right?
If we already knew that we want to go all the way into here, then we can actually specify the entire
path to get there.
For example, right now I'm inside Learn,
let's go back to our route so I can say "cd ~" and hit Enter.
And now I'm back at my root directory, which is here.
Let's map out the path that I need in order to get to here.
I need to go into Documents and then Learn and then Languages. So I can simply write "cd Documents/
Learn/Languages".
And now if I hit Enter, I am inside languages, which is over here
and that's a lot more succinct and a lot quicker than going through the directories one by one.
Another really time-saving feature of the terminal is the up ↑ and down ↓ buttons,
so if you wanted to use the last command that you typed, all you have to do is just hit the up button
and you can see that I can use that change directory command again.
But in my case I actually want to use the ls command.
Obviously, it's easier to type out ls, rather than cycling through all those
but I just want to show you that you can actually go through your entire history of previous commands
and you can then hit Enter to execute it. And you can see that inside the Languages folder,
I have two other folders called German and IPA, so you can tell that we are at this level in our directory.
Now, sometimes typing out an entire path like this might seem like it's a lot of work,
so I want to show you another neat trick that you can use when you have the Finder open and you just
want to navigate to a deep directory without having to type out the entire path.
So let's cd back to here, to our root directory for your user.
Do you remember how to do that?
If you do, go ahead and do it now.
So I'm going to cycle back and I've found it,
it's the cd ~,
and if I hit Enter, I am now back at my user's root directory.
Now once we're inside this Languages folder, how do we change directory back to the parent folders?
How do we go backwards in this path?
We're still going to be using the change directory or the cd command, and then after a space, we're
simply going to type two dots (..) and this takes us back one level.
So from Languages, I'm now in the Learn folder, so I'm now here and I can keep doing this until I'm
back at my root directory, right here.
So it took me three cd .. to get back to my root.
And the reason why you might want to do this is because, say, if I was inside the Languages folder,
so I'm now at the Languages directory and I wanted to navigate now to my Music directory
for example. I can't simply write "cd Music", that's not going to work because it's looking inside this
Languages folder.
It's looking to go forwards.
So if I wanted to go backwards in the directory, I would have to specify the entire file path to go
backwards
and I can only specify just the name of the folder if I'm going forwards in terms of this hierarchy.
Now, what if I wanted to edit this at some point in the middle of this entire command?
Because you can see that if I click at any of these places, it doesn't really do what you expect it
to do in a graphical user interface, right?
Namely, allowing you to edit these parts.
Your cursor is here and you can only type where your cursor is.
So you can of course use the left arrow to go all the way back,
but this is obviously very time-consuming, especially if your command is very long.
So a neat trick is holding down the Option or the Alt button and it gives you this little plus sign (+)
and now you can click on one point in your command and you can now move the cursor to that position.
So that's quite a neat trick as well.
Now for people who have come from a long history of using graphical user interfaces such as, you know,
your Mac OS or your Windows having these little tricks, like using the Option Click can be quite neat,
but if you are a puritanical command line user, then ideally you're aiming for never having to touch
the mouse. And you can do most things that you would want to do with the mouse very easily and quickly,
just using your keyboard.
For example, if I wanted to go to the beginning of this line, then I can simply hold down Ctrl
and press A. So my cursor is now at the beginning, and if I hold down Ctrl and press E, then I go
to the end of my command line.
Now you've already seen that I can cycle through my previous commands by using the up and down buttons,
but what if I wanted to clear this current command without executing it?
So to do that you can again hold down Ctrl and hit the U button and that clears your entire line
so you can write a new command.
So in the next lesson, we're going to cover directories, making directories and secret folders.
So I will see you there.