NodeJs

Introduction To Command Line Tools & List of Some Basic Commands

Introduction to command Line windows and MacOS and some basics command

In the previous knowledge bit, we have discussed that how we can set up NodeJs runtime environment in our Machine and learned to create basic Hello World application. Now in this NodeJs tutorial, we are going to learn about Command Line tools and introduce some of very important command line commands.

Introduction To Command Line Tools

What is Command Line?

Let start our tutorial by discussing what command line is. So the command line is the text-based interface to interact with your machine. By using the command line, you can perform many commands to do precisely what you want. From command you can delete, edit folder navigates through files and folders on your machine.

So with the command line, you can do everything that you can do with your mouse with visual menus like making the new file, saving a file, running a file or opening an application, you can do all that through the command line. We will use Command line to run node server. One of the advantages of using Command line is that it is much faster.

Now we have talked about what the command line is and why it is important and useful. Now we are going to discuss some important command and we will see that how we can use that command. We are also going to use these commands in our upcoming NodeJs tutorials. So the first thing we need is a folder where we navigate, create and delete the file so let’s create a folder.

Inside the folder, we will create a text file, and inside that file, we will write a simple text message. So go ahead and run command line or terminal according to your machine.

What are command line tools? how its works command prompt terminal

LS:

LS stands for list and LS command used to list all the files and directories in the folder we are in. It shows all the content of the currently selected folder.

So when I typed ls in our PowerShell window, I got the list of directories and folder.

ls command - list down the directory and folders using command line and terminal LS

 

If we create another folder inside NodeJs folder, and a text file and then write ls in PowerShell window then we get the following output.

 

Command line and terminal check repository directories

 

You can notice that we have got three files two folders and one text file.

 

CD:

The next important command is cd and cd is used to change directory, it takes directory name as an argument and then switches that directory. So first we write CD and then name of the folder or directory that we want to change into.

 

cd command - change directory using CD command, Terminal Command line prompt

 

Now, you can notice that our directory is changed to command line. Now if we want to go one step back then we write cd..

 

CD command Navigate through directories on macOs and windows

echo:

Touch command is used to create the new file inside the working directory. So echo followed by $null >> and then it takes the name of the command that we want to create an argument and then it will create a new and empty file. We are going to create an HTML file inside the command-line directory.

 

echo command - Create new file using Command line or terminal command on MAcOS and Windows

 

You can notice that first, we navigate from folder NodeJs to CommandLine using cd.. and then create an empty HTML file.

 

Mkdir:

Mkdir is a directory which is used to create the new folder in a working directory. We write mkdir followed by <space> and then write folder name as an argument and create the new folder. So now if we want to create three folders with name HTML, CSS and JavaScript inside CommandLine folder then we write Mkdir and then name of the folder that we want to create.

 

mkdir command - Create new folder and directory using command line on Windows and MAcOS

 

You can notice that we have created three folders in the folder CommandLine. Now we have 5 items inside that folder.

rm:

rm stands for remove and we use this command to delete the specified file. If we want to delete the hello.html file from CommandLine folder then we write rm and then the file name that we want to delete.

 

rm command - delete particular file on windows and MacOS using command line command

 

Now, you can notice that hello.html file got removed from command line directory. We have four files left in this directory.

Rm –r:

r is used to delete the whole directory. Rm and rm –r is the same command line command where –r is the modifier so if we want to delete the CommandLine folder then we write rm –r CommandLine.

 

rm -r command - delete all the file using command line command on mac and windows

 

You can we have only two items left in our NodeJs folder. The CommandLine and all of its child items are removed.

Conclusion:

In this NodeJs tutorial, we have given the introduction to command line tools and we have gone through different command line command. We have seen that how we can create and delete folders and different file using the command line commands.

 

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

To Top