Think of an image: Developers staring at a black screen with white or green text flashing, writing code and trying to hack into the corporate frame. Does this image sounds familiar?
That black screen is the command line interface (CLI).
Other terms that refer to the Command Line Interface (CLI) are: Terminal, Shell, Command Prompt, Bash.
In this CLI is where you enter the commands that the computer will run. Working with the command line is essential skill to learn as a developer. It is the base of our operations meaning that it is from where we can launch other programs and interact with them. The command line has its own syntax, but since you are going to enter the same commands over and over again, then it is a matter of time to learn the most important ones and the ones you will need most.
In this lesson you will learn some basic operations we can do from the command line such as navigate around the computer and manipulate files and directories (also known as folders). The commands that you will learn in this lesson are very simple and straightforward so there is nothing to worry about.
Open a terminal on your computer.
CTRL + ALT + T
on your keyboard.Before we do anything, take a look at the following text:
$ whoami
Every terminal command starts with a $
. This symbol tells our computer to execute what comes after the $
. This means that we must excluded it when we enter a command. So in the example above we will only type whoami
in our terminal. So open your terminal, type whoami
and press enter on your keyboard.
It returns your username. Cool you have just wrote your first command.
Throughout this curriculum we will use the command line very often. We will going to install various software using the command line and you will use Git within the command line. In addition in your career as a software developer you will use the command line on a daily basis, and thus learning that skill early on it will be an asset.
touch
command.ls
(the l
is a lowercase L
). The ls
command will show you the files and folders in the current directory (or will show nothing if the current directory is empty).ls
test.txt
by entering this in your terminal: touch test.txt
.touch test.txt
Now enter ls
once again. You should see test.txt
listed in the output. You can also create more than one file at once using the touch
command.
Enter touch index.html script.js style.css
and press the enter.
touch index.html script.js style.css
ls
once more. You should see the files in the output.This is a small indication of how powerful the terminal is. It would have taken much more time if we had created those files with the mouse. Thanks, terminal!
Now it’s time to take a break for 10 to 15 minutes, and then start reading the 1st chapter of Conquering the Command Line
.
Serve yourself a hot cup of tea or coffee and dedicate the next few hours to discovering and using the Command Line. Make sure to test the commands mentioned in the book on your local terminal.
Read & Execute: Chapter 1 of Conquering the Command Line.
Programmers in general are lazy. If they are using the same command over and over again they will find a way to automate it. For this reason there are a lot of shortcuts out there, that they have been created from developers, that you can use and benefit from.
Duration: 12 minutes
One problem that you might already have encountered is that copying and pasting inside the terminal doesn’t work as usual. In order to copy and paste something you need to use Ctrl+Shift+C
(Mac: Cmd+C
) to copy and Ctrl+Shift+V
(Mac: Cmd+V
) to paste. You can test it by highlighting a command text from the browser, use Ctrl+C
to copy it and then use Ctrl+Shift+V
to paste it in the terminal.
Another useful tip is the tab completion. This tip will save you a lot of time since it helps you to navigate quicker to a folder. For example let’s say you need to move to a folder that is located in ~/Documents/FrontEndDevelopment/Web-Development-101/javascript/calculator/
. As you see this is a long command to type out and thus by hitting Tab
, the command line will automatically complete commands as you are typing them, once there’s only one option.
Let’s see an example: If you type cd D
then you probably have two folders the Documents
folder and the Downloads
folder. So the command line will show you these two options.
$ cd D
Documents/ Downloads/
$ cd D
However if you continue typing a little more you will be able to write the full path with just typing cd DocOWjcal
. Just test it out and see how it works.
There is also another handy shortcut the .
. This command will help you open every file within a project. For example if you have VSCode installed you can type cd
into the project directory and then type code .
(with the period) to open up all of the project files. In addition this shortcut is also used with Git. For example we use the git add .
command to add all the files inside of a directory into Git’s staging area.
Now it’s time for an exercise. You will create directories and folders and then delete them. You will create those files using the terminal.
my-directory
.my-directory
directory.my-file.txt
.my-directory
directory.my-directory
directory.If you have successfully done those steps you have understood the basics of the command line. Keep in mind that is more efficient to move and copy files through the command line. As you continue using the command line more often then you will get used to it and you will feel more comfortable.
In this section you can find a lot of helpful links to other content. This is a supplemental material for you if you want to dive deeper into some concepts.
A great resource is this video made by one of our students Kiuri Waddington Negrao that shows how to create a Bash script that initializes a project directory, creates some basic boilerplate for web development and initializes it as a git repository. All this running on a Windows machine:
Duration: 11 minutes
Bash aliases are essentially shortcuts that can save you from having to remember long commands and eliminate a great deal of typing when you are working on the command line.
The online book Learn Enough Command Line to Be Dangerous is a great resource for mastering the command line. Chapter 1 is free and provides a good introduction to command line tools. The rest of the book is not free and goes into more depth than you really need at this point, but feel free to purchase and read the rest of the book if you like.
ExplainShell.com is a great resource for if you want to deconstruct a particularly strange shell command or learn how Bash works through guess-and-check.
Unix/Linux Command Cheat Sheet contains a list of important commands that you can refer to regularly as you become familiar with using Linux. You can print it out so you can have a physical copy with you when you’re not at your computer.
Command Line Flashcards by flashcards.github.io.
Video Series from LearnLinxTv contains 24 videos explaining the basics of the command line. Videos are brief enough for beginners but, at the same time, are detailed enough to get started and light your inner curiosity.
Now it is time to check your knowledge and your understanding of this lesson. If you stuck in a question just click the small arrow to the left and an answer will be revealed.
CTRL
+ ALT
+ T
.cd
command to change directories.cd
on its own navigate you to?cd ..
navigate you to?pwd
(print working directory) command.ls
command. Use ls -l
to display the files in a list.mkdir
command.touch
command, e.g., touch new-file.txt
.rm
command. To destroy folders, use rm -r
or rmdir
.mv
command, e.g., mv folder/old-file.txt folder/new-file.txt
.