How to Use the Command Line Interface (CLI)

Issa Sangare
Dec 20, 2020 · 6 min read

There is a saying that says: “you can truly call yourself a developer if you know at least how to use the command line”, base on that saying let me walk you through the basics of the command line.

At this point, it’s assumed that you have already the CLI installed on your computer. About Mac’s users, you have already the command line application. If you’re not familiar with CLI and don’t know how to get access to the terminal, visit the following website: “”. For windows’ users, you will need to install it and there are so many tutorials out there, please just google “how to install command line tools windows”.

What’s the Command Line Interface?

The command line interface is a program on your computer that allows you to create and delete files, run programs, and navigate through folders and files. On a Mac, it’s called Terminal, and on Windows, it’s Command Prompt.

In this tutorial, we are going to walk you through some of the commonly used command line commands. To recall, for the rest of this lesson whenever we refer to directory we just mean folder.

1. pwd (Print Working Directory):

Syntax : pwd + enter/return

Where are we? In the terminal, you are always working in a directory, or folder, on your computer. First things first, let’s use pwd command to find out my current working directory. pwd shows us that we are inside my root directory which is issasangare's folder.

2. ls (List): ls is the command which lists all files and directories in the current working directory.

Syntax : ls+ enter/return

3. ls -a : Lists all contents in the working directory, including hidden files and directories.

Syntax : ls -a+ enter/return

4. cd (Change directory)

a) To navigate from one directory to another: We use cd command and it takes a directory name as an argument, and switches into that directory.

Syntax : cd <name of the directory> + enter/return. Now let us navigate to my Desktop folder.

Let’s check out my current working directory by using pwd command.

At this point, we can use ls command to list all files and folders that are inside my Desktop.

b) To navigate from one directory to the root directory:

Syntax : cd + enter/return.

In this example, we have used first pwd to print my current working directory and then cd command. Once in my root directory, we have used pwd command one more time to display my working directory which is my issasangare’s directory.

5. cd .. (Change directory one level back)

Syntax : cd .. + enter/return.

In this example, we started inside my docs directory, which is located inside bootstrap-4.0.0 folder, which is also inside Desktop directory and finally my Desktop which is located inside my root directory. First things first, let us find out where we are by using pwd command.

For the next step, we have used cd .. command to navigate one level back and then pwd which shows that we are inside my bootstrap-4.0.0 directory.

And finally, we used cd .. command again to navigate from bootstrap-4.0.0 toDesktop directory which is also one level back and then printed out my current working directory by using pwd.

6. mkdir (Make a directory)

Since we are at my Desktop directory, let us create a new directory and name it coding. We are going to use mkdir to create a new directory, it takes in a directory name as an argument and then creates a new directory in the current working directory.

Syntax :mkdir <name of the directory to be created> + enter/return

After creating coding directory and cd into it, let’s use the service of our good friends pwd and ls commands to print out my current working directory and check out if there is any file or folder inside coding directory. It turns out that we are inside coding folder and it’s an empty directory.

7. touch (Creating file)

In our new directory created coding which is empty, let us create some files in it. We are going to use touch, it takes in a file name as an argument, and then creates a new empty file in the current working directory.

Syntax: touch <file name to be created> + enter/return

In this example, we used touch command to create a new file named text.txt inside coding directory and then ls to list files or folders of coding directory. We can see it below, coding folder has only one file which is Text.txt .

8. open (Opening file)

To open a file we use open command.

Syntax:open <the name of the file to be opened > + enter/return

9. rm (Removing file)

To remove a file, we use rm command.

Syntax:rm + <the name of the file to be removed> + enter/return.

10. rm * (Removing several files)

Syntax : rm *+ enter/return.

Back again in coding directory, we have created three new files(Text1.txt, text2.rft & Text3.js) and used rm * command to delete all files located inside coding folder in go. After using rm *, we have used ls to check out if it remains any file or folder inside coding directory and it turned out it’s an empty folder.

11. rm -r (Removing directory): Deletes a directory and all of its child directories.

Syntax:rm -r + <name of the file to be deleted> + enter/return.

This time around, we are going to use rm -r command to delete coding directory. Since we cannot delete a directory while inside that same directory, let us first navigate to myDesktop directory where coding folder is located and use rm -r.

12. mv (Moving File): To move a file into a directory, we use mv command with the name of the file as the first argument and the destination directory as the second argument.

Syntax:mv <name of the file to be moved> <destination directory name>. In this example, we have created first aaa.txt inside our root directory and then used the commands mv to move it into Desktop folder.

We have reached the end of this tutorial, I hope you found this informative and useful. Thanks for reading!!

P.S: My next blog’s topic is: “Understanding Version Control & git”. stay tuned.