Developers Best Friend: Command Line Interface

Command-line Interface(CLI) is a software that allows us to communicate with our systems(computers). By giving commands to the CLI we can instruct our systems to perform a variety of tasks. For example — Creating, deleting, copying, moving files, folders, launching editors, installing, and managing new packages, dependencies, version controls (Git), etc.

CLI is an integral part of any developer's life as it helps in accelerating the development process. Working with CLI initially can be quite intimidating because it doesn't necessarily provide an appealing User Interface, but it definitely is one of the easiest to work with.

In this article, I will be discussing the basics of the Command-Line Interface that every developer must know. Also, different operating systems like macOS, Linux, Windows comes with different CLI’s and use different commands. In this article, I will be discussing the commands for Windows.

Note — The commands used here are not the only way(exact) of doing things, I will try to give you the easiest way of doing them.

In Windows, We will be using Powershell. To open Powershell — Goto Start and Search ‘PowerShell’ and open it.

Windows Powershell

Note C:\Users\Dell (yours can be different) simply refers to the path in which the Powershell is currently working i.e it is your working directory. In simple terms, Now if you give any commands for creating files, folders, etc then all of those actions will be performed in that C:\Users\Dell folder.

So as to understand it more clearly I want you to manually navigate to your current path. Open File Manager or My Computer then, In my case go to C drive →Users →Dell folder. (go to your current path)

C:\Users\DELL

To see the list of all files and folders present in the working directory use the command — ls (press enter).

  • ‘ls’ simply means list.
ls (enter)
  • As you can see ls will give me the list of all files and folders present in the working directory (C:\Users\DELL). (You can make sure by matching the previous picture with this list).

So as to change your current working directory/folder, Use command — cd path. (then press enter)

cd cd means change directory/folder.

path — path refers to the destination of the new folder.

Let us Assume — There is a folder named ‘Test’ that is present at the Desktop and we want to move to that folder — cd Desktop/Test

cd Desktop/Test

Note —

  • Now you can see that my working directory changed to — C:\Users\DELL\Desktop\Test.
  • Also, \Desktop\Test got appended (added to the end) of C:\Users\DELL, simply because there was a directory(folder) named Desktop in C:\Users\DELL.
See Desktop was present in C:\Users\DELL.
  • To move out, one level back of the working directory i.e. — from Test folder to Desktop use the command — cd .. (enter)
cd .. (enter)

As you can see now my working directory changed to — C:\Users\DELL\Desktop

  • To move back multiple folders at the same time use the command — cd ../../(as many times you want to move up)
cd ../../ (enter)
  • cd ../../ — will take you two levels back the working directory. (from Test to DELL).
  • cd ../../../ — will take you three levels back the working directory and so on.

Now, Suppose the ‘Test’ folder is initially ‘empty’.

Note — It doesn’t necessarily have to, It can already have files and folders inside of it, But for this tutorial, we will assume its empty as we will create files and folders in it with the help of Powershell.

Also, make sure your working directory is C:\Users\DELL\Desktop\Test. As whatever command you write gets executed in the working directory.

For creating a new folder use the command — mkdir name-of-folder.

  • ‘mkdir’ means make directory.
  • name-of-folder — whatever you want to name the folder, I will name it folder1, Although it can be anything.
mkdir folder1
  • To check whether the folder was created or not I used ls as it lists all files and folders present in the directory. You can also check manually by moving into the folder.

For deleting a folder, use the command — rmdir name-of-folder.

  • ‘rmdir’ means remove the directory.
  • name-of-folder —The name of the folder you want to delete. Suppose we want to delete folder1’ the folder we just created.
rmdir folder1 (enter)
  • To check whether the folder was deleted or not I used ls and it doesn't give me any output as the folder(Test) is now empty. You can also check manually by moving into the folder.

To create multiple folders at the same time — mkdir name-1-folder,name-2-folder,…

I am going to create 4 folders simultaneously as — mkdir folder1,folder2,folder3,folder4

To delete multiple folders at the same time — rmdir name-1-folder,name-2-folder,…

I am going to delete 2 folders ‘folder3’ and ‘folder4’ simultaneously as — rmdir folder3,folder4

Now Suppose you have been writing commands on Powershell for some time and your screen looks congested as in the picture above, So you can clear your screen using the command — cls or clear

  • ‘cls’ or ‘clear’ simply means clear the screen.
cls or clear (enter)

Now Suppose we want to create a new file in the folder1, So first we need to navigate to ‘folder1’ as — cd folder1, Then

For creating a new file use the command — New-Item name-of-file.extension

  • New-Item It helps us to create new files.
  • name-of-file — Whatever you want to name the file
  • Extension — Type of file. (.html,.css,.js.py, .txt etc).

For deleting an existing file use the command — Remove-Item name-of-file.extension

For creating and deleting multiple files at the same time simply separate filenames with ‘,’.

These were the basics of the command-line interface that every developer must know. But there is a lot more to command-line-interface like copying, moving files, launching your editor, working with version controls, etc and I will be discussing them in the upcoming articles. Stay Tuned!!!

Web Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store