Understanding the command line and how to use it effectively is your very first step in becoming a web developer for the modern world. That first step, ironically, is to abandon your mouse and start using only your keyboard to operate on your computer, like cutting and pasting files and folders, and downloading a file entirely from the command line. In a sense, just like a magician would perform a spell by chanting words, you will execute a process (like moving and copying files) in the computer using nothing but a blank screen and a keyboard. Many programming courses and blogs in the Internet assumed you know how to use command line as a software developer, so learning even only its basics will give you a leg up in your tech career. You can think of this guide as the rite of passage from “non-tech” people into “tech” people, since working with the command line is something you will do daily when you have transitioned into a full time working developer. An example command you might find online looks like this:
$ npm start
But please don’t feel pressured by the intimidating black screen! The command line is inside your computer before the computer screen with clicks and buttons you see everyday today, and those buttons and clicks are actually just that — an interface that allows you to give commands to the computer. Let me tell you another secret: You don’t have to learn everything about the command line in order to be a developer. The truth is web developers rarely used 100% capability of the command line. Indeed, most of the time we used it only for starting an application, navigating or copying files.
I have two important tips to tell you as you begin with this series:
Just keep moving forward.
In any programming guide you go through, you will encounter things that are frustrating and hard. But part of any learning is that it will be hard in the beginning. As you keep going and learning, you will get better with time, and things will be easier. I know because I went through it all before becoming a professional developer myself. So no matter how hard it is, please don’t give up halfway, because you are learning the most valuable skill in the 21st century.
Type in the commands.
It will be very tempting to copy and paste all the sample code as you go through with this guide. Don’t do it. The point of this guide is to make your brain and hand learn how to read and write command lines. Trust me, repetition will make you great.
Unix Command Line
Before we went further with this guide, I have to mention something that needs your attention. This tutorial requires you to be able to run Unix command line on your operating system. Unix is basically a group of operating system that includes Linux, Android, iOS and macOS. So, if you are using either a Mac or Ubuntu PC you are good to go. If you are using Windows, then you need to install either Windows Subsystem for Linux or Git Bash to get Unix command line.
Now you might already have some knowledge about Git or you might be wondering what Git is. At this point it doesn’t matter whether you know about Git or not. What you need to know is that Git for Windows will install a Terminal program which can run Unix commands.
WSL For Windows 10
If you are using Windows 10, you can install WSL or Windows Subsystem for Linux in order to run Linux distro on Windows. For more explanation you can visit WSL documentation here.
Installing Git to use Git Bash
If you’re using Windows version below 10, then another way to get Unix Command line is by installing Git. Go to Git Download page and click the one for Windows. You can follow the installation process wizard without changing any of the options. Just click next until it’s finished. Then go into your desktop and do a right-click with your mouse on the screen. You will see Git Bash Here on the menu.
This Git Bash will allow you to execute Unix command on windows. Try run this command.
$ touch document.doc
By the way, you’ve just mastered how to create a file using Unix command. Congrats!
Be advised that for all the command lines we will discuss in this course will be run from the Home folder so that we can see the results. Let’s move on into the next module and find out.
Your First Command
We are all used to having graphical interface (buttons and menus) for interacting with our computers. For example, the Explorer window where we can navigate our hard drive, view all files stored on a folder, creating, copying, and moving folders and files all around our system. You know, right click on a file and then click on open, copy, or delete with your mouse? What if I tell you that you can do the same thing only without the mouse? And I don’t mean by hitting delete on your keyboard! That’s no fun. What I want to tell you is that you can do the same thing with the command line — viewing, copying, moving files and navigating the computer folders — but without the graphical interface on top of what we are doing. Also instead of moving mouse pointers around and clicking on shiny graphics, we have to type out what we are going to do. The default program that lets you type commands on a computer varies according to the operating system you installed on your computer. Try to open your command line program and check it out.
Every terminal program would look like the example above. The [username@computer] part is a placeholder, so what you see will be different and will show the values you have saved. The dollar sign
$ is a prompt that indicates where you can start typing your commands. It will always be followed by a cursor. In a lot of programming tutorials, you will see commands formatted like this:
$ type these commands
Programming tutorials used
$ sign to signify that you are to run this command in the terminal. It’s just a common sense among software developers. Now let’s type our first command to test this out. Type the following command into your terminal:
$ echo hello world
echo is the first command we are using here, and it works just like the name itself. It sends back response exactly identical to what you write. After the command you will see another $ sign, meaning that the command has been done by the terminal, and you can type another command.Let’s try to write some more words.
$ echo hello world !
$ echo 'hello, world'
$ echo "hello, terminal"
Now it isn’t really exciting to just echo words, isn’t it? This is just to give you a taste of using the command line. Let’s move on and start using the command line like a real developer.