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: “https://www.businessinsider.com/how-to-open-terminal-on-mac”. 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):
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
2. ls (List):
ls is the command which lists all files and directories in the current working directory.
3. ls -a : Lists all contents in the working directory, including hidden files and directories.
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.
cd <name of the directory> +
enter/return. Now let us navigate to my
Let’s check out my current working directory by using
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:
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
5. cd .. (Change directory one level back)
cd .. +
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
For the next step, we have used
cd .. command to navigate one level back and then
pwd which shows that we are inside my
And finally, we used
cd .. command again to navigate from
Desktop directory which is also one level back and then printed out my current working directory by using
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.
mkdir <name of the directory to be created> +
coding directory and
cd into it, let’s use the service of our good friends
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.
touch <file name to be created> +
In this example, we used
touch command to create a new file named
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
8. open (Opening file)
To open a file we use
open <the name of the file to be opened > +
9. rm (Removing file)
To remove a file, we use
rm + <the name of the file to be removed> +
10. rm * (Removing several files)
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.
rm -r + <name of the file to be deleted> +
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 my
Desktop directory where
coding folder is located and use
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.
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
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.