The terminal without fear
The terminal is the black window full of text that hackers type into in movies. It has a scary reputation, but it's really just another way of telling your computer what to do. Instead of clicking on things, you type short commands.
You don't need to become a terminal expert. In this lesson you'll learn a handful of commands, and honestly, that's most of what you'll need for a long time.
Why bother?
If you can do everything by clicking, why would you type commands instead? A few reasons:
- Some tools only work in the terminal. Git, which you'll learn later in this pathway, is mostly used from the terminal.
- It's often faster. Once you know a command, typing it takes a second.
- Instructions online use it. Almost every setup guide you'll ever follow says something like "run this command". Now you'll know what that means.
Opening the terminal inside VS Code
Your computer has its own terminal app, but the easiest place to use it is right inside VS Code. That way it's always next to your code.
Open it with View and then Terminal in the menu, or press Ctrl+` (that's the key with the backtick, usually just below Escape). This shortcut is the same on Windows and Mac.
A panel opens at the bottom of the window with a line of text and a blinking cursor. That line is called the prompt. It's the terminal saying "I'm ready, what do you want me to do?"
A nice bonus: when you open the terminal in VS Code, it automatically starts in the folder you have open. So you're already in the right place.
On Windows the terminal is usually PowerShell, and on Mac it's usually zsh. They're slightly different, but every command in this lesson works in both.
Where am I? pwd
The terminal is always "standing" in a folder, just like a file explorer window always shows one folder at a time. To find out which folder you're in, type this and press enter:
pwd
It stands for print working directory. "Directory" is just another word for folder. The terminal answers with the full path to the folder you're in, something like /Users/alex/projects/first-page.
What's in here? ls
To see the files and folders in the current folder, type:
ls
It's short for list. If you're in your first-page folder from the last lesson, you'll see index.html.
Moving around: cd
To move into another folder, use cd, which stands for change directory, followed by the name of the folder:
cd projects
To go back up one level, to the folder that contains the one you're in, use two dots:
cd ..
Two dots always mean "the folder above this one". And a single ~ (a tilde) means your home folder, so cd ~ takes you home from anywhere.
Here's a trick that saves a lot of typing: start writing a folder name and press the Tab key. The terminal fills in the rest for you. If nothing happens, there's either no match or more than one, so type a few more letters and try again.
You're in the folder projects/first-page. Which command takes you back to projects?
Select one answer
Making folders: mkdir
To create a new folder, use mkdir, short for make directory:
mkdir my-new-folder
You won't see any message when it works. That's normal. Many terminal commands stay quiet when everything goes fine and only say something when there's a problem. Type ls to check that the folder is there.
Opening things in VS Code: code
This one is really handy. From the terminal, you can open a folder in VS Code like this:
code .
The single dot means "the folder I'm in right now". So this opens the current folder in VS Code.
On Windows this works right away if you checked Add to PATH when you installed VS Code. On Mac you need to turn it on once: open the Command Palette, type shell command and choose Shell Command: Install 'code' command in PATH.
Cleaning up: clear
When the terminal gets full of text, type clear to wipe the screen. It doesn't undo anything, it just gives you a fresh, empty view.
You typed mkdir photos and the terminal printed nothing. What happened?
Select one answer
Your cheat sheet
Here's everything from this lesson in one place:
pwd where am I? ls what's in this folder? cd name go into a folder cd .. go up one folder cd ~ go to my home folder mkdir name make a new folder code . open this folder in VS Code clear clear the screen
And one golden rule: never run a command you don't understand, especially one you found online that starts with sudo or deletes things. When in doubt, look it up first. Every command in this lesson is completely safe.
Open the terminal in VS Code and try this sequence, pressing enter after each line:
pwdto see where you arecd ~to go to your home foldercd projectsto go into your projects foldermkdir terminal-practiceto make a new folderlsto check that it's therecd terminal-practiceto go into itpwdagain to see that you movedcd ..to go back up
Use the Tab key to fill in folder names as you go. If you get lost at any point, pwd tells you where you are and cd ~ always takes you home.