Coding Hub  /  Tools

the terminal

Move between folders and run files without touching the mouse. Six commands cover almost everything you will do this year.

Getting started

What it is and how to open one.

01 What the terminal is

A terminal types commands at your computer instead of clicking at it. Everything you do in a file manager — list a folder, move a file, open a program — has a typed equivalent, and the typed one can be repeated, scripted and shared.

You need it because most developer tools have no window: Python, Node, Git and npm are all commands, and the terminal is where you run them.

Open one inside VS Code with Ctrl+` — the backtick above Tab. It starts in whichever folder you have open, which saves most of the navigating below.

what it is called
SystemProgramLanguage
MacTerminal, or the one in VS Codezsh
LinuxTerminalbash
WindowsPowerShell, or the one in VS CodePowerShell
Windows (alternative)Git Bash, installed with Gitbash — matches Mac and Linux

02 The prompt, and where you are

The terminal is always somewhere — in one folder, called the working directory. Commands act on that folder unless you say otherwise.

This is the single idea that makes the terminal click. “File not found” almost always means the file exists but you are standing somewhere else.

When a command cannot find a file, run pwd and ls before anything else. Nine times out of ten the answer is there.

Terminal
pwd
# /Users/ada/projects/plant-tracker      <- Mac and Linux
# C:\Users\ada\projects\plant-tracker    <- Windows

ls          # list this folder (Mac, Linux, Git Bash)
dir         # the same, PowerShell and CMD
ls -la      # long listing, including hidden files like .env

Moving about

One command, three forms.

03 cd

cd changes directory. It takes a path, and the path can be relative to where you are or absolute from the root of the drive.

Press Tab. Type the first two or three letters of a folder name and press Tab — the terminal completes it. This is not a nicety: it stops almost every typo, and it only completes names that actually exist, so it also tells you when you are in the wrong place.

Terminal
cd plant-tracker      # into a folder that is here
cd ..                 # up one level
cd ../..              # up two
cd ~                  # your home folder
cd /                  # the root of the drive
cd -                  # back to where you just were
cd                    # on its own: home folder

# A path with a space needs quotes
cd "My Projects"

04 Reading a path

Three symbols appear in paths constantly and each means one thing.

A path starting with / or a drive letter is absolute: it works from anywhere and nowhere else. A path starting with a name or a dot is relative to where you are standing.

path symbols
SymbolMeansExample
.the folder I am in./script.py
..the folder above../index.html
~my home folder~/Desktop
/separates folders; alone at the start, the rootcss/styles.css

Doing things

Create, move, delete, run.

05 Files and folders

You can do all of this in a file manager. Learn the commands anyway, because they are the version you can put in instructions for someone else.

rm does not use the recycle bin. There is no undo and no confirmation. Read the line twice before pressing Enter, especially if it contains * or -r.

Terminal
mkdir my-project          # make a folder
mkdir -p src/js           # make nested folders in one go

touch index.html          # make an empty file (Mac, Linux, Git Bash)
New-Item index.html       # the same in PowerShell

cp styles.css backup.css  # copy
mv old.html new.html      # rename, or move

rm notes.txt              # delete a file. No undo.
rm -r old-folder          # delete a folder and everything in it

06 Running your programs

The command is the program's name, then the file. Both have to be findable: the program on your PATH, the file in the folder you are standing in.

Terminal
python hello.py           # run a Python file
python3 hello.py          # on systems where 'python' is version 2

node app.js               # run a JavaScript file
npm install               # install a project's dependencies
npm run dev               # run a script from package.json

python --version          # check a program is installed
node --version
git --version

Working faster

The parts nobody tells you.

07 Keys worth knowing

These six save more time than any other thing on this page. The arrow keys alone will halve your typing.

keys
KeyDoes
TabCompletes the name you are typing
↑ ↓Walks back through commands you already ran
Ctrl+CStops whatever is running. Use it on a hung program.
Ctrl+LClears the screen. clear does the same.
Ctrl+A / Ctrl+EJump to the start or end of the line
Ctrl+RSearch your command history — type part of an old command

08 Windows and the rest

PowerShell understands many Unix names as aliases, so ls and cd work. The ones below are where they genuinely differ.

Installing Git for Windows gives you Git Bash, a terminal that uses the Mac and Linux commands. If you are following a tutorial written for a Mac, use Git Bash and the commands match.

differences
Mac / LinuxPowerShell
ls -lals -Force
touch file.txtNew-Item file.txt
cat file.txtGet-Content file.txt
rm -r folderRemove-Item -Recurse folder
pwdpwd — the same
/ in paths\, though / usually works too

09 Errors you will meet

Six messages cover nearly everything the terminal will say to you.

message to cause
What you seeMeans
command not foundThe program is not installed, or not on your PATH. Check with --version.
No such file or directoryYou are in the wrong folder. Run pwd then ls.
Permission deniedThe file is protected, or you are writing somewhere you may not.
cd: not a directoryYou tried to cd into a file.
The prompt does not come backThe program is still running. Ctrl+C stops it.
A > prompt you cannot escapeAn unclosed quote. Press Ctrl+C and retype the line.

10 Ten minutes of practice

Do this once and the commands stop needing to be looked up.

try it