-: Now before we can use the exciting tools
that I showed you in the last lecture,
we need to learn a bit about the command line.
Yeah, you heard that right.
These tools only work in the command line.
And so now comes the time where
you finally have to learn about it,
at least the basics like moving around
in the file system, creating files and folders,
copying files and stuff like that.
And I know that many, many people are afraid
of the command line for some reason, and
I was afraid myself some years ago.
I admit it.
But now I love the command line
and I really can't live without it really.
And so can't any serious web developer.
It's just part of the job, okay?
Now if you already know this stuff
then please feel free to move on to the next lecture
as you probably are not gonna learn anything new here.
But for the rest of us, let's get to it.
Now the command line works a bit differently
whether you're on Windows, Mac, or Linux.
So on a Mac, it is called terminal,
and so let's open it up by opening up the terminal app.
Make it a bit bigger so you can actually see me typing.
And that should be okay.
Now on Windows the command line is called command prompt,
and you can open it up by right-clicking on the start button
and from there choose the command prompt.
Now the commands are also a bit different
on Windows and on Unix, which is Linux and Mac.
So here I'm gonna type the ones for Linux and Mac,
but I'm gonna tell you the ones for Windows
as we go so that if you're on Windows,
you can follow this video as well.
So that being said, the main concept of the command line
is that we're always in a folder.
And right now I'm here in the home folder and
I can see the contents of this folder by running ls.
And on Windows it's called dir which stands for directory.
So, like this, but on the Mac and Linux for that matter
it is called ls, which is for list.
So in my home directory, I have these eight folders here.
And now I can actually move into these folders.
So in the command line I can use commands
to move up and down in my folder structure.
So I'm on the desktop now and so let's say
we want to get into the desktop
because that's where the project folder is.
So you see, here on my desktop is where I have this folder
for the project that we're gonna work on in this section.
And so now here in the command line
I can also move into that folder.
In order to do that I have to use cd, so change directory.
And this one is actually the same on Windows.
So I write cd and then I write desktop.
Hit return, and now I'm in the desktop folder.
And you actually can see it here.
So it changed here from this home folder
which is what this here means to the desktop folder
which is now the current folder or
the current working directory.
So I can do ls again or dir on Windows remember.
And now I see the contents of the folder.
Now to move into this one here again I use cd.
And then I can write the name of the folder.
Now if I start writing it like this,
then I can also hit the tab and it will then automatically
complete the rest of the path for me because
if I started writing 9 f then there's really
no other path here that it could be
and so automatically the command line
knows that this is what I'm trying to write.
Now if you have some folder names that are similar
in the beginning, then you have to write the name
of the folder until it is different from all the others.
And only then you can hit the
tab button in order to auto-complete.
So now I'm in the forkify folder here,
let's use ls again and so you see
the dist and source folder that I showed you before.
Now if you actually wanted to move up, we can also do that.
And again we use cd and then we use dot dot.
So dot dot always means the folder above.
We are in the forkify folder now
and if I execute this command,
then we're back in the desktop.
But let's actually move back into it.
And if you don't want to repeat the same command
that we wrote before, we can use the up and down
arrow keys on the keyboard in order to
run through the commands that we wrote before.
So, just like this.
So you see all of the commands that I wrote before.
This is the one that we want to
move back into the forkify folder, right?
Ls just to make sure that
we have the right folder names here.
Now this is now getting a bit cluttered here and
so we can actually clear this up by writing simply clear.
At least here in a Mac command line.
On Windows you have to write cls.
So cls like this.
So I write clear and then
I am back to having this clear command line.
Let's now actually make a new folder here
in this forkify folder, so I'm writing mkdir,
which stands for make directory.
And again, this one is the same on Windows.
So let me call this one here test.
And so now we should see that we have three folders
so dist, source, and test.
And we can confirm this by opening up the folder here
in the explorer and here it is.
Here is the folder that we just created in the command line.
Now moving into that folder, so cd test, we can now create
a new file in here also using the command line.
So on Mac and Linux the command is called touch
and then the name of the file that we want to create.
So let's say I want to create test.js.
Now on Windows it is a bit different, so
let me tell you how it is on Windows.
On Windows we have to write copy null
and then the file name.
Let's say also test.js.
And this is actually only with one l,
so this is not a mistake, it's not two "l"s, not like this.
It's actually just like this.
So it sounds a bit weird, maybe, but this is how it works.
So that's on Windows of course I'm not gonna execute it here
so I'm just gonna get rid of it.
But right now here if I'm in this test folder and do ls,
I'm going to see this newly created file in here.
Let's create another one.
Touch jonas.js.
And indeed now both of them are here.
And again I can confirm this here of course in the explorer.
So jonas and test.js.
Nice.
So what can we do now next?
Well, let's copy jonas.js into the main folder.
So how can you do that?
Well it's actually very easy.
We just need to use the cp command.
And on Windows it's simply called copy.
So just like this.
So cp, the name of the file, jonas.js,
and then the directory.
And I want to copy it into the parent folder,
and remember how we write the parent folder,
well, just these two dots, right?
So, let's execute it.
Move up into the forkify folder and then let's check it out.
And indeed, we have dist, source, and test folders
and then the jonas.js file that I just copied here.
So again I'm gonna confirm it and
here it is and of course it's still here
because we didn't move it, we did copy it.
And since we're talking about moving, let's then go back
into this folder and move the other file
out of the test folder into the home folder.
So, cd into test and now to move
we use the mv command on the Mac and on Windows, just move.
So mv, the test file, and actually this also works
with files, so I can simply hit the tab key
and it auto-completes the file name here as well.
So mv test.js to the parent folder so dot dot again,
and here we go.
Now if I do ls here now we should
only have the jonas.js file left.
And indeed here we go, and if you go up,
well you already know that it worked, I'm sure,
and indeed now test and jonas.js are both here.
So that's how we create folders and files
and copy and move them.
Now as a final step, let's also
learn how to delete these files.
So from here I'm going to delete jonas.js and test.js.
So in order to do that I'm going to use the rm command.
So rm jonas.js, and again auto-complete,
and then I can hit return.
But be careful here, because this remove command
will actually remove it permanently
so it will not move it to the trash but instead
it will delete it immediately from your hard drive
and it's gone forever.
So be really careful with this command, okay?
And on Windows this one's actually called del so delete.
So rm and I hit return and now it should be gone.
Let's confirm it, and indeed it is gone.
And actually I could have done both of them at the same time
so jonas js and test js here in the same command
but that's now simply do it separately with
the test.js right now and so finally they are both gone.
Now let's clear this command line again,
move into the folder and then remove this file here as well.
So this file, or actually we can do better.
We can simply delete this entire folder containing the file,
and this way I can also show you how to delete folders.
So let's actually go back.
Let's take a look here.
And so we wanna get rid of this test folder.
So on a Mac, you simply do rm again for remove,
but then you have to use an option or a flag,
which is the r, which stands for recursively.
And this means that it will one by one
delete all the files in the folder and
then the folder as well.
So rm minus r, which stands for the flag r, and then test.
Now let's check it out.
And now it's gone.
Now on Windows, this works a bit differently.
And it work like this.
So it's rmdir,
then slash S, and
then the name of the directory.
So it would be something like this.
Not going to do that of course.
So now we're back to the original state of our folder.
Just one more thing that I want to show you is
how to open files directly here from the command line.
So let's move into the source folder, cd source.
And in here should be the index.html file.
Yeah.
And so let's now actually open it,
and it's as simple as using the open command.
And on Windows you use start instead of open.
Okay, so simply start just like this.
So index, then tab to auto-complete, and now it should open
in the default program which in this case is Google Chrome.
So let's try it.
And here we go.
So that's the index.html file here.
It's unstyled because it's not connected with the CSS,
but, yeah, so it actually open up the file that we ask for.
So, I think that's the really basics
that I had to show you here with the terminal.
So again this is really important stuff to learn
because all the tools that we're gonna use next
are run directly from the command line.
So you really need to have some basics of course.
So I hope this lecture gave you these basics
and so let's now move on together right to the next one.