How to use the Command Line
In this lesson, we are going to learn how to use the Command line or the terminal in Windows or Mac So let's get started. The first command that we're going to look at is called LS
, which is to list the items which are inside the folder you're already in. If you see below in a screenshot. I'm inside the Azizali's folder and the list of items are showing as I used the LS
~
represents the home directory of the user which is logged in.
If you want to go to the very root directory of your machine, you can simply write cd /
and hit enter and you will be inside the main directory of the machine.
If you want to see what's inside your main directory of that machine you can simply write LS and you can see the folders inside the director as shown below
If you want to go to any folder which is inside the directory, you can simply write cs users
since I want to go to the users folder. You can see below, I'm in the users folder.
If you want to see what's inside the azizali's folder I can say LS
and you see it shows three folders. And if I want to go in any of the folder, I can write cd azizali
and you see I'm inside the azizali's folder. Also you notice the tilde sign ~
is back because I'm in the directory.
You can write clear
to clear up the screen, but you can still scroll up and see the previous information. If you want to go back, one step up you can simply write cd ..
or if you want to go back, you can write cd Desktop
and you will be back to the desktop as shown below.
You can also create a folder in that particular location by writing making a directory like such mkdir
and call it anything you like, I'll call i iloveNode hit enter and you see the folder gets created.
If you want to go inside that folder you can simply write cd iloveNode
and you will be in that folder. If you want to open that folder you can write open .
and you see the folder got open.
This only works in machines, which have windows kind of environment. If you're on core terminal based machines like Linux or Unix without the Windows. This isn't going to happen, because they don't have the GUI.
If you want to create a file inside the folder that you created, you can write touch
and the name of the file like such touch first.js
If you want to remove the file, you can write rm
and name of the file in our case it will be rm first.js
hit enter and the file will be removed. If you want to write something inside the file, you can write echo
and write something in quotes like such echo "firstline"
the greater than sign and the name of the file like such echo "FirstLine" > first.js
save it, refresh the file and you will see the FirstLine got printed in the file. You can also use that to replace the text. If you want to write something else, you can add double greater than signs
If you want to change the name of the file, you can simply write mv
the name of the file that you want to change, then write the new name of the file like such. mv first.js second.js
you can see the file name got changed to second.js
If you want to move that file to the desktop, you could write mv second ../
name of the file and your file will be moved to the desktop.
If you want to see what's inside the file, you can write cat
and the name of the file like such cat second.js
whatever the content of the file was got printed.
I hope you enjoyed this lesson, If you have any question, leave your comments below. I'll talk to you in the next lesson. Goodbye :)
Get Started
Already have an account? Please Login