A big part of being a developer is being able to use the terminal or the command line.
Well, what is it? In this video we're going to tackle this question and teach you a couple of very useful
commands.
Now on a Mac you simply do command space (CMD-Space) and type in 'Terminal'.
Press 'Enter' and then the terminal will open for you.
It's one of your applications and it's on every computer.
If you're on a Windows machine then it is the command prompt and I'll leave instructions at the end
of this video of how you can access them but you might remember this from the Traceroutes video earlier on
in the course.
But what is it? Well, it's how humans originally communicated with computers up until the 1980s.
It was the main way humans gave instructions to computers and computers gave output to the humans.
We didn't have something called the GUI or the Graphical User Interface such as me opening up a new
folder and changing the name of this folder or opening up Google Chrome.
I don't really need to know how this is done behind the scenes.
I just click on an icon and it opens it up magically for me.
But command lines are really useful because you can do the exact same thing that you do visually on
a Graphical User Interface like I have here on the command line but they tend to be much much faster
to do as I'm going to show you in this video.
And there are also common ways to access different computers around the world, like if you need to access
a server in another country where your web app is hosted.
Well you'd use the command line and I'll show you how to do that later on in the course.
Now in your day to day job you'll be using the terminal a lot because you'll have to access servers
the database your front-end application.
But you can do all of that in one from the terminal.
You can also download scripts that other people have written from the internet so you can use in your
project.
Now these are all things I'm going to show you in the later sections.
The commands that I'm about to show you work on a Mac or Linux. For Windows,
I'll have the Windows version command at the bottom of the video as we progress,
most of them are the same but there are a few differences.
So let's get started.
The first command I'm going to show you is the 'ls' command.
I simply type in and press enter and it lists everything that is in my current directory.
What is my current directory?
Well, I do 'pwd' for Present Working Directory and I see that I'm in the '/Users/' , that's my user name,
so I'm in my username folder and these are all the things available to me.
If I do 'cd' then I can go into this. If I wanted to go to, let's say, desktop,
I do 'cd Desktop'.
And now if I do 'ls', I see that I have 'untitled folder', because that's the only thing on my desktop right
now.
I can also do 'cd ..'
and this brings me back to one directory up.
I can also do 'clear' to clear up my terminal and have a nice fresh slate. There's a short command 'cd /'
and this takes me to the root directory.
If I do 'ls', I see that I have 'Applications, Library, System, Users..'
That's the root directory of my Mac, essentially my Macintosh HD.
I can also do 'cd ~' and this takes me to the user directory.
Let's clear this again.
And if we check where we are.
All right, let's change this 'untitled folder' to something like 'test', okay?
Let's say I'm in the user directory right now, I want to access 'Desktop' and then the 'test' folder.
I would simply do 'cd Desktop/' and then 'test'. And now I'm in the 'test' folder, but there's nothing
in there.
So one thing we can do is I can say 'open .' and it opens a folder that we're currently in. Okay, we're
in the 'test' folder.
Now if I just put this to the side over here so you can see, I can say 'mkdir(make directory)', which is make a
folder 'name'. So 'name' here will be whatever I want the folder to be titled. Let's just say this folder
would be called 'webapp'.
Did you see that?
Now 'webapp' shows up in my folder. Let's change the view here so you can see it better.
There you go.
If I do 'ls' now, I see that we have the 'webapp' folder and as we know, we can go into it. Let's double
click here to see what we have.
We have absolutely nothing.
Well, We can create a file in here by saying 'touch' and the name of the file.
So let's just do 'index.html'.
There you go,
'index.html'
Now what if we wanted to open this 'index.html' again, we just do 'open' and the '.(dot)' means we open
the folder we're currently in which is here.
But if I do 'open index.html', it opens the file for us.
How cool is that?
But 'index.html' is pretty empty right now.
Wouldn't it be nice if we could open Sublime Text from here and add something? Again, you can do that with 'open'.
You put in 'a', so '-a' for application and the name of the application, so 'Sublime Text'. Close the double
quotes, press enter, and look at that.
I have Sublime Text. But if we wanted to do,
'-a(application) Sublime Text' and open the 'index.html' file. We just do this.
And now I can say 'html', and it will just say 'Helloooo world!'
Save that.
And if I do 'open index.html',
We have our 'index.html' file loaded.
Wasn't that a lot faster than right clicking, creating a folder, then dragging everything to Sublime Text.
And as you can see, you can do things really really faster.
OK, let's change something.
Let's - I'm going to close Google Chrome and Sublime, and in the 'webapp', let's say I wanted to change the name
of 'index.html' to 'about.html'.
Well, I'll do the 'mv' command, which stands for 'move',
but it just moves 'the index.html' file to 'about.html'.
So it's a little trick -
You're essentially just moving one file to another but, by changing the name, you create a new file and
you replace it with the old one.
So now I have 'about.html'.
Very cool.
Now these commands typing them can get pretty tiring.
I can press the up arrow and it goes through my entire history, which is very cool. I can also press the tab
key and it will bring up my most recent commands or completes what I'm about to write so you can do it
really really fast.
And when your commands get longer and longer it's a very useful thing to do.
OK.
I don't really need the 'about.html' file anymore.
Let's remove it.
We do 'rm', for 'remove', and the name of the file 'about.html'.
It's been removed.
Perfect.
Now, what about the 'webapp' file, we can remove that as well.
But if I just do 'rm webapp',
well, it's not going to work.
First of all if I do 'ls' or 'pwd(present working directory)', I'm in the 'webapp' folder.
So I need to move back to the 'test' folder.
Let's clear here.
Do 'cd'.
Now, my 'pwd(present working directory)' is - I'm in the 'test' - so I can remove 'webapp' by doing 'rm webapp'.
But 'rm' only works for files. To remove a directory or folder,
You need to do 'rm' and then use the '-r' option
and then the folder name, in our case's the 'webapp'.
There you go, it's gone.
And with that, you know what, we can remove the 'test' folder as well.
We can go back to our 'Desktop' and then do 'rm -r test'.
There you go, it's gone.
And one last trick on a Mac.
You can do this.
Right?
Very very cool.
As you can see, you can have a lot of power with the terminal. And I want you to get used to writing commands
on here. And from now on, try creating files and folders this way.
Eventually you'll get more and more comfortable with it and things will be much faster than
just using the GUI. In the developer environment section,
I'll show you how you can change this boring black and white terminal to something like this.
That's it for now.
See you in the next video.
Bye-bye