This is a post for those who are right at the beginning of their coding journey, who have come across the command line perhaps whilst following a tutorial, and have been slightly intimidated by it.
You can do a lot at the command line, but what we are concerned with here is getting a general idea of what it is and a feel for working with it. This post is not just about giving you a list of basic commands.
Please note that I am myself a newbie, so I am approaching this subject through that particular lens. Also, as I have not had personal experience with Linux yet, this post covers the use of Microsoft Windows 10 and Mac operating systems.
As a beginner, you don't need to do much at the command line, but knowing what it is will make it slightly more familiar when you do come across it. You could be following a tutorial, for example, which asks you to install a program or run a file from there.
It is certainly worth taking a look at, in order to gain a concept of it and how it works, for when you do hear or read about it later.
I will loosely define some terms, so you can refer back here if you need check a definition whilst reading this post:
- Console - the window where you type text commands into your computer. It can also be called the command line interface.
- Command - an instruction you type in for the computer to act upon.
- Prompt - the text or character you see at the command line that is prompting you to type something in. It might end with a
$dollar sign, or have a blinking square.
- Command Prompt - the name of the Windows command line interface.
- Terminal - the name of the Mac command line interface.
- Graphical User Interface (GUI) - the usual interface you use to interact with your computer using windows, icons and buttons.
- Directory - a location for storing files, such as a folder or drive.
- Path - the unique location name of a file/folder/directory on your computer.
(please note there do exist longer, more specific definitions of these, but I'm aiming to keep things as simple as possible here)
Why not open the console/command line interface on your computer right now and take a look at it?
With Windows, type
cmd into your search bar at the bottom left of your screen. You can also press
Windows + R, and then type
cmd into the Run window.
With Mac, open your Applications folder, then Utilities & double-click on Terminal, or press
Cmd + spacebar to launch Spotlight & type Terminal.
The command line is basically a text-based way of talking to your operating system and the applications on your computer.
You can complete the tasks you normally do with your GUI by using menus or clicking icons in different windows. You can install programs, look inside directories, create and run files, and much, much more.
This is a quicker way to complete certain tasks, particularly if they are labor-intensive, for example renaming a whole batch of files. Often system administrators and IT professionals use it to get larger tasks done, and it can also be accessed remotely by them.
Certain commands are typed into the console via your keyboard (no using the mouse here!) and you simply press
Enter. You may get a reply, depending on the command. It could provide information you ask for, tell you it has completed a task, occasionally ask you a question, or it may give you an error message, if it doesn't understand your command.
Sometimes you might not get a reply at all, as it makes a change behind the scenes, for example when you are creating a new folder, or deleting one, which we will cover in a moment.
Here are a few things you can learn to do right now:
One of the simplest things you can learn to do at the command line is how to navigate around inside your computer.
When you first open the console window, the command line should tell you where in your computer it is sitting at that moment. This is also known as a path.
When I open mine I see:
So I know I am currently sitting in a folder on my computer called
zoela, in a folder called
Users, on my
C: drive. (Yours obviously won't be exactly the same - it will tell you where it is sitting in your computer.)
To help you understand where you are, you can open your File Explorer (Windows) or Finder (Mac) in your GUI and navigate to the same place. The command line directories mirror the ones in the GUI.
Think of the directories as part of a tree - here my
C: drive is the trunk, and
Users is a branch, and
zoela is further along the branch.
In order to see what is inside the directory you are in, for Windows, type:
For Mac, type:
When you use this command, the screen will print a list of everything in that directory. Again, you can look in the equivalent place in your GUI and you will see all the listed files and folders in graphical, icon form.
Now, you can try to move about, or change directory, by moving further along the branch. For both Windows & Mac, type
cd and then the name of the directory you want to move to. It could be any folder that is within the folder you are currently in - you will have a list of them on the screen from the previous command you ran. So, if I want to move to my desktop, I type:
Now the command prompt will change and show you being in this new directory, with an updated path.
(Note that the command line tends to not be case-sensitive, so you could type
desktop and you would still get to the same place.)
Mine now says:
This shows I have moved further along the imaginary tree branch, with another step further away from the trunk.
If you want to navigate the other way and back out of a directory, type:
This will take you back one folder/directory, or one step closer to the trunk of your tree again.
Remember, at any point, you can type
dir (Windows) or
ls (Mac) to screen print a list of what is inside that directory, which can help you get your bearings.
We have looked at how you move up and down a branch one directory at a time, which is nice and simple when you are just starting to do it, but there are some quicker ways of moving from one directory to another.
A useful command is:
(Note this is a forward slash, not a backslash)
This will take you right back to what is officially called the root directory - though I personally find it easier to imagine this as the trunk of a tree.
So my path now says simply:
Moving all the way back here makes it easier to now navigate up a different branch to a different directory using
cd and the next directory name, as we did before.
However, you can also take a leap (like a squirrel!) from one branch to another, without having to go back to the trunk/root directory.
In order to do this, you type
\ (backslash), then the path of the location you want to go to, including all the relevant backslashes.
If you aren't sure how to write it out, navigate to that folder in your Explorer or Finder with your GUI, and you should be able to see and copy the directory path from that window.
Here is an example. I am currently at:
I want to go to:
So I type:
And it takes me there.
The command prompt will tell me that I am now sitting in that directory.
Note that I didn't have to type
C: as part of the path, because we were already on that part, the trunk, (or root directory). You only need to trace the path back to the first location that is shared with the branch you are currently sitting on, in this case the
It is worth opening your console window and giving this a try as you read it. It will be much easier to understand if you actually do it.
Have your Explorer or Finder GUI window open at the same time in another window, if it helps you picture what you are doing.
Practice moving up and down directories, from the branches to the trunk and back, and maybe up and down a different branch, until you get the idea. Get the console to print a list of what is in the directory, if you want help to figure out where to move to next (as covered above).
So now you know how to move around your computer. Being able to do this is helpful in understanding how things are laid out, and how they mirror the GUI, even if you don't do much with it at this point.
Some good commands to know are ones that help you when working in the console window itself, because you will just be using the keyboard and not your mouse.
- To clear the console window (a busy screen can be distracting):
up arrowto cycle up through the previous commands you've typed, to save you re-typing something. Just press
enterwhen you get to the line you want. The
down arrowcycles back through the opposite way.
Ctrl + Cor
Cmd + Cgets you back to the command prompt if you end up inside a different program inside the console. You will know this has happened if you don't see your directory name, as you would normally expect to, at the prompt. It will be showing something different, eg.
>>>>In that event, try this.
Ctrl/Cmd + A- will move the cursor to the beginning of the line
Ctrl/Cmd + E- will move the cursor to the end of the line
Ctrl/Cmd + U- clears the entire line, in the event you make a mistake and want to retype it
exit- exits the console completely and closes the window
In order to make a folder in a certain directory, you need to be inside it first, so the first thing to do is to navigate there, as you learned earlier.
When you give commands to your computer at the command line, it will execute them in the directory it is currently sitting in, unless instructed otherwise.
For both operating systems, the command for creating a new folder is the same: (please note - where I have put
name_of_folder, type the name of your folder)
This will create a folder, with this name, in the directory you are currently sitting in.
You will not get a response from the command line to say it has been done, so you can check it is there by asking for a list of your current directory contents - typing
ls, as you learned earlier.
You can also look in the GUI directory to see that it is mirrored in these too.
The command for removing a folder is also the same for both operating systems:
This deletes the folder. (Be careful with this command - you don't want to delete something you need!) Once again, you can check it has been done by asking for a list.
This is just a simple example of how you can change things within your computer from the command line.
There is much more you can do, so if you feel confident, you can check out other tutorials covering this subject.
You might come across a tutorial where it asks you to install applications and programs from the command line. If you do, follow the tutorial and type in exactly what they suggest. If there is a
$ sign, type in whatever text comes after that.
You might find, however, that some commands don't work, as they may be for a different operating system. This has happened to me a few times.
If they aren't working for you, type them into Google, or another search engine, with the name of your operating system, eg. Windows 10, Mac etc.
I have found this is the best way to work out what to type into the console, if the tutorial you are using hasn't provided you with alternatives.
Lastly, something else that is often done at the command line is version control. Newbies won't really need to do this, but you may be curious to understand how pull requests etc. work when you sign up to GitHub, like I was.
I would recommend if you are just starting out with GitHub and experimenting with version control, that you download and use the GitHub desktop GUI at first, as that takes care of the command line part of the process for you. Once you understand the version control process itself, it will be easier to tackle it all from the command line.
Well done for getting this far!
I hope that this post has given you a feel for the command line and also shown you that you don't need to feel intimidated when you open the console.
Thank you for reading. Good luck with your coding journey!