The terminal from zero (PowerShell and macOS Terminal)

Learn the terminal from zero in PowerShell and macOS Terminal side by side: the prompt, cd, ls, mkdir, paths, PATH, exit codes and Ctrl+C.

Tool lesson, about 60 minutes, 17 steps

By the end you can

  • Open a terminal on Windows or macOS and read its prompt to know where you are.
  • Move around and create folders with cd, ls or dir, and mkdir, using tab completion and history.
  • Run a program, explain PATH, read an exit code, and stop a running program with Ctrl+C.

Before this: Your computer: requirements, files, folders and paths

1A window that takes orders

Later in this course you will start Beacon Yard's code syncing into Studio by typing two words, rojo serve, and pressing Enter. You will push your work to GitHub with git push. Neither of these has a button. Both happen in a terminalTerminalA window where you type commands and read the replies.Think of it as the counter window you speak through to a clerk who runs your order.: a window where you type a command, press Enter, and read the reply.

The terminal looks old-fashioned, and that is part of its strength. Typed commands can be copied, pasted, written down and repeated exactly. Every professional tool you meet later works from it.

First, open one.

Windows 11. Right-click the Start button and choose Terminal. Windows Terminal opens with a PowerShell tab 1. On Windows 10, open Start, type PowerShell and choose Windows PowerShell.

Windows Terminal
Windows Terminal with one PowerShell tab showing the prompt PS C:\Users\you>

Select a numbered pin, or a row below, to read what it marks.

Figure 1.1.

Windows Terminal, PowerShell tab. The prompt shows the folder you are in.

macOS. Press Command + Space, type Terminal and press Return. The Terminal app lives in Applications, in the Utilities folder 2.

macOS Terminal
Illustration of macOS: Terminal window showing the title bar and a zsh prompt ending in a percent sign.

Select a numbered pin, or a row below, to read what it marks.

Figure 1.2.

macOS Terminal running zsh. The % ends the prompt. Illustration of macOS.

Build along

m00-baseplate

  1. Open a terminal using the steps for your system and leave it open for this lesson.

    You should see A window with a blinking cursor after a line ending in > (Windows) or % (macOS).

Open this step in lesson mode · Link to this step · This confused me

2Read the prompt

The text before the cursor is the promptPromptThe text before the cursor that says the shell is ready, and where you are.Think of it as the clerk saying 'Next!', with the number of your folder on it.. It means "ready for your next command", and it tells you where you are standing:

text
PowerShell:  PS C:\Users\you>
macOS zsh:   you@mac ~ %

PowerShell prints the full path of the current folder, then >. The macOS shell, zsh, prints your user name, the computer's name, the current folder's short name, then %. The ~ is your home folder.

The folder you are standing in is the current directoryWorking directoryThe folder the terminal is standing in; relative paths start from here.Think of it as where you are standing at the counter., or working directory. Every relative path you type starts from there, exactly like the directions in the previous lesson.

Your prompt reads PS C:\Users\you\Code\beacon-yard>. Where are you?

  1. In your home folder
  2. In the beacon-yard folder inside Code inside your home folder
  3. In the C drive's root
  4. In a file called beacon-yard
Answer

In the beacon-yard folder inside Code inside your home folder. PowerShell prints the full path of the current directory before the >. Here that is the beacon-yard folder.

Open this step in lesson mode · Link to this step · This confused me

3Ordering at the tool counter

Both sidesThe terminal is the workshop's tool counter, where a clerk does one ordered thing and reports back.
In the pictureIn Roblox
The clerk saying 'Next!'The prompt
The orderThe command
The details of the orderThe arguments and options
Where you stand at the counterThe current directory
The receiptThe exit code
The stockrooms the clerk searchesThe folders listed in PATH

See the whole analogy cast

Picture the tool counter at the back of the yard's workshop. The clerk behind it does exactly what you ask, as long as you ask in the clerk's words.

  • The prompt is the clerk saying "Next!".
  • A commandCommandThe name of the program or built-in job you ask the shell to run.Think of it as the name of what you want from the clerk. is the name of what you want: ls, cd, git.
  • ArgumentsArgumentA detail you give a command, separated from it by spaces.Think of it as the details of your order. are the details of your order, separated by spaces: in cd src, the argument is src. Arguments that start with - are called options or flags, such as --version.
  • Where you stand at the counter is the current directory.
  • When the job is done, the clerk hands you a receipt that says whether it worked. You will read that receipt later in this lesson.

Think of it as The workshop's tool counter, where a clerk does one ordered thing and reports back

Take the command git commit -m "Add coin pad". Match each piece to its role.

  1. git
  2. commit
  3. -m
  4. "Add coin pad"
Answer

git: The program to run; commit: An argument: which Git job; -m: An option (flag); "Add coin pad": An argument with spaces, kept together by quotes. The shell splits the line at spaces, except inside quotes. The first word is the program; the rest are its arguments.

Open this step in lesson mode · Link to this step · This confused me

4Where am I, and what is here?

Two commands answer the two questions you will ask most:

QuestionPowerShellmacOS zsh
Where am I?pwd (short for Get-Location)pwd
What is here?ls or dir (short for Get-ChildItem)ls

PowerShell accepts the short Unix-style names as aliases of its own longer commands, so most of this lesson types the same thing on both systems 3. What comes back looks different: PowerShell prints a table with a Mode column, where d marks a folder; macOS prints the names alone.

Try it in the sandbox first. It is a pretend computer, so nothing you type there can harm yours.

The terminal sandbox

The terminal sandbox: a still of the simulation
Figure 4.1.

Build along

m00-baseplate

  1. Optional, for real: Run pwd (or Get-Location), then ls, in your real terminal, starting from your home folder. If you are somewhere else, run cd ~ first.

    You should see pwd prints the full path of your home folder, and ls lists what is in it, including your Code folder.

Open this step in lesson mode · Link to this step · This confused me

5Move with cd

cd means change directory. Give it a path, absolute or relative:

text
cd Code            go into the Code folder (relative)
cd ..              go up one level
cd ~               go to your home folder
cd C:\Users\you    absolute, Windows
cd /Users/you      absolute, macOS

The prompt changes after each cd, which is your confirmation that it worked. If the folder does not exist, you get an error and you stay where you were.

The terminal sandbox

The terminal sandbox: a still of the simulation
Figure 5.1.

Build along

m00-baseplate

  1. Optional, for real: From your home folder, run cd Code, then pwd. Then run cd .. and pwd again.

    You should see After the first cd, pwd ends in Code. After cd .., pwd is your home folder again.

Open this step in lesson mode · Link to this step · This confused me

6Let the shell type for you

Typing whole paths is slow and error-prone. Two keys fix that.

Tab completes names. Type cd sr and press Tab: if only one name in the folder starts with sr, the shell finishes it to src (PowerShell writes .\src\). If several match, PowerShell cycles through them each time you press Tab, and zsh lists them.

The Up arrow brings back your previous commands, one press at a time. Edit the line with the Left and Right arrows, then press Enter to run it again.

Professionals rarely type a full file name. Tab completion also prevents typos, because it can only complete names that really exist.

You type cd Con and press Tab, but nothing happens. What is the most likely reason?

  1. Tab only works on macOS
  2. No name in the current folder starts with Con, or you are in the wrong folder
  3. The folder name is too long
  4. You must type the extension first
Answer

No name in the current folder starts with Con, or you are in the wrong folder. Tab completes names that exist where you are standing. Silence means nothing there matches, so check where you are with pwd and what is there with ls.

Open this step in lesson mode · Link to this step · This confused me

7Make folders with mkdir

mkdir makes a directory. It works on both systems, with one difference that catches people out:

text
mkdir notes                    both: makes notes in the current folder
mkdir src/client               PowerShell: makes any missing folders on the way
mkdir -p src/client            macOS: needs -p to do the same

Names with spaces need quotes, because a space separates arguments: mkdir "my notes" makes one folder on both systems. Without quotes, mkdir my notes does something unexpected on both: macOS makes two separate folders (my and notes), while PowerShell prints an error (A positional parameter cannot be found that accepts argument 'notes') and makes nothing (to make two sibling folders in PowerShell, separate them with a comma: mkdir my, notes). This is why the last lesson suggested names without spaces.

The terminal sandbox

The terminal sandbox: a still of the simulation
Figure 7.1.

Build along

m00-baseplate

  1. Optional, for real: Inside your Code folder, create scratch/one/two with a single command (add -p on macOS), then cd into two and run pwd.

    You should see pwd ends in Code/scratch/one/two (with backslashes on Windows).

Open this step in lesson mode · Link to this step · This confused me

8Peek inside a file

You can print a text file's contents without opening an editor:

text
cat README.md          macOS
cat README.md          PowerShell (an alias of Get-Content)

To make an empty file, macOS uses touch notes.txt and PowerShell uses New-Item notes.txt. You will rarely need either, because your editor creates files for you. Reading a file with cat is handy for small files like .gitignore.

On macOS and Linux, names that start with a dot, such as .gitignore, are hidden until you run ls -a. On Windows, a leading dot does not hide a file on its own, so plain ls in PowerShell already shows .gitignore; only items marked with the Windows Hidden attribute (such as Git's .git folder) require ls -Force.

On macOS, inside the beacon-yard folder, ls shows README.md and src, but you know there is a .gitignore. Why is it missing?

  1. It was deleted
  2. On macOS and Linux, names starting with a dot are hidden until you run ls -a
  3. ls only lists folders
  4. It is inside src
Answer

On macOS and Linux, names starting with a dot are hidden until you run ls -a. A leading dot hides a file on macOS and Linux until you pass -a. On Windows PowerShell, plain ls already shows .gitignore, while Hidden-attribute items such as .git need ls -Force.

Open this step in lesson mode · Link to this step · This confused me

9Run a program by name

Good place for a break. Your answers and progress are saved in this browser, so you can stop here and come back to this step. Tick what you can do now; if something is shaky, go back one step first.

Checkpoint

  • I can read my prompt to know which folder I am in
  • I can move with cd and look with ls and pwd
  • I can make folders with mkdir

Every command so far was built into the shell. Most of the time you will run programs: git, rojo, code. You type a program the same way, by its name and arguments.

Try one now. Git may not be installed yet, and that is fine, because an error is useful information.

text
git --version

There are three possible results:

  • git version 2.x.y means Git is installed and the shell found it.
  • On Windows, "The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program" means the shell could not find a program called git.
  • On macOS, a window may offer to install Apple's command line tools, which include Git 4. Accepting is safe; the Git lesson relies on it.

Build along

m00-baseplate

  1. Run git --version in your real terminal and note which of the three results you got.

    You should see You see a version number, a 'not recognized' or 'command not found' error, or the macOS install prompt. All three are fine for now.

Open this step in lesson mode · Link to this step · This confused me

10PATH: where the shell looks

How does the shell find git when you never said which folder it is in? It checks a list of folders, in order, and runs the first file whose name matches. That list is an environment variableEnvironment variableA named setting that every program started from a shell can read.Think of it as a sticky note pinned to the shell that all its programs can see. called PATHPATHThe environment variable listing the folders the shell searches for programs.Think of it as the list of aisles the clerk checks, in order, for the tool you named. 5.

text
PowerShell:  $env:Path -split ';'
macOS zsh:   echo $PATH | tr ':' '\n'

Each command prints the folders one per line. Windows separates them with ; and macOS with :.

Two rules follow from this, and they explain most "it says not found but I just installed it" moments:

  1. An installer that adds a tool to PATH changes it for new terminals. A terminal that was already open keeps its old copy. Close it and open a fresh one.
  2. If a tool is installed but not on PATH, you can still run it by typing its full path.

In the counter picture, PATH is the list of stockrooms the clerk searches, in order.

You install Git, go back to the terminal you already had open, and git --version still says 'not recognized'. What do you try first?

  1. Reinstall Git
  2. Restart the computer
  3. Open a new terminal window and try again
  4. Edit PATH by hand
Answer

Open a new terminal window and try again. The open terminal copied PATH when it started, before the installer changed it. A new terminal reads the updated PATH.

Open this step in lesson mode · Link to this step · This confused me

11The receipt: exit codes

Every program ends by handing back a number, its exit codeExit codeThe number a program hands back when it ends; 0 means success.Think of it as a receipt that says whether the job worked.. 0 means success. Anything else means something went wrong; the exact number is the program's choice.

PowerShellmacOS zsh
Last program's exit code$LASTEXITCODEecho $?
Did the last command succeed?$? (True or False)(same $?, 0 is success)

In PowerShell, $LASTEXITCODE holds the exit code of the last native program you ran, such as git 6.

You will rarely type these yourself. They matter because automation reads them. When GitHub tests Beacon Yard, each check is a command, and a non-zero exit code is what turns the check red.

Both sidesRemember: The terminal is the workshop's tool counter, where a clerk does one ordered thing and reports back.

The terminal sandbox

The terminal sandbox: a still of the simulation
Figure 11.1.

Build along

m00-baseplate

  1. Optional, for real: Run cd nowhere, then show the exit code (echo $? on macOS, $? in PowerShell). Then run cd Code and show it again.

    You should see The first cd prints an error and the code is not 0 (False in PowerShell). After the cd that works, the code is 0 (True in PowerShell).

Open this step in lesson mode · Link to this step · This confused me

12Stop, copy and paste

Some programs keep running until you stop them. rojo serve is one: it keeps syncing until you tell it to quit. Press Ctrl + C to stop the running program, on Windows and on macOS. The shell prints ^C and the prompt comes back.

That collides with copy and paste, so learn the terminal versions:

Windows (Windows Terminal or the PowerShell window)macOS Terminal
Stop the running programCtrl + C (with no text selected)Control + C
Copyselect text, then Ctrl + C or Ctrl + Shift + CCommand + C
PasteCtrl + V or right-clickCommand + V

Paste one command at a time and read it before pressing Enter. Windows Terminal warns you before pasting several lines at once, because each line runs as soon as it lands. The older Windows PowerShell window on Windows 10 does not warn you, so be extra careful there.

rojo serve is running and printing messages. You want your prompt back. What do you press?

  1. Ctrl + Z
  2. Ctrl + C
  3. Escape
  4. Close the window and reopen it
Answer

Ctrl + C. Ctrl + C asks the running program to stop. Closing the window works too, but it throws away your history and current folder.

Open this step in lesson mode · Link to this step · This confused me

13Where the counter idea breaks

A good clerk asks "are you sure?" before doing something drastic, and keeps returns in a back room for a week.

The terminal does neither. rm notes.txt on macOS and Remove-Item notes.txt in PowerShell (also spelled rm) delete the file immediately. They do not move it to the Recycle Bin or the Trash, and they do not ask first. Add -r or -Recurse and they delete whole folders the same way.

Where does it break?“The workshop's tool counter, where a clerk does one ordered thing and reports back” is a good picture of the terminal. Where does it stop being true?

It breaks here. A real clerk asks 'are you sure?' and keeps returns, but the terminal does exactly what you typed: deletions skip the Recycle Bin and there is no undo.

The true model. A shell reads a line, finds the program by name in PATH, runs it with the arguments in the current directory, and reports its exit status. It never asks for confirmation unless the program does.

You run rm -r src by mistake inside beacon-yard. How do you get the folder back?

  1. Open the Recycle Bin or Trash and restore it
  2. Press Ctrl + Z in the terminal
  3. From a copy that exists somewhere else, such as Git or a backup; the terminal itself cannot undo it
  4. Run rm -r src again to toggle it back
Answer

From a copy that exists somewhere else, such as Git or a backup; the terminal itself cannot undo it. Terminal deletes skip the Recycle Bin and have no undo. This is one reason the Git lesson matters: committed work can be restored even after a bad delete.

Open this step in lesson mode · Link to this step · This confused me

14Which terminal, which shell?

Two words get mixed up. The terminalTerminalA window where you type commands and read the replies.Think of it as the counter window you speak through to a clerk who runs your order. is the window. The shellShellThe program inside a terminal window that reads your commands and runs them.Think of it as the clerk behind the counter; the window is just the counter. is the program inside it that reads your commands. Windows Terminal can host several shells in tabs, and macOS Terminal runs zsh by default on macOS 10.15 and later 7. Studio still runs on macOS 10.14, whose default shell is bash: if your prompt ends in $ instead of %, type zsh and press Enter first, and every macOS command in this course works as written.

Shells you will meet

OptionWhat it isWhen pros pick itTrade-offs
PowerShellThe shell that comes with Windows. Its own commands have long names like Get-ChildItem, with Unix-style aliases. All Windows commands in this course are written for it (the Windows default).Any Windows machine, with nothing extra to install.Tutorials written for macOS or Linux need translating.
zshThe macOS default shell. It uses the Unix commands (ls, mkdir -p, rm) that Linux and most online tutorials also use (the macOS default).Any Mac, with nothing extra to install.Its commands differ from PowerShell's, so follow the macOS column of this course on a Mac.
Git BashA Unix-style shell installed with Git for Windows. Paths look like /c/Users/you.You prefer Unix commands on Windows, or follow tutorials written for macOS and Linux.You translate this course's Windows commands as you go.
Command Prompt (cmd)The old Windows shell.Mostly legacy scripts.It still works but uses different commands (dir, cd /d, no ls). Avoid it for this course.

Windows Terminal is open with a Git Bash tab. Which commands apply?

  1. PowerShell commands, because it is Windows Terminal
  2. Unix-style commands like ls and mkdir -p, because the shell is Bash
  3. Only cmd commands
  4. None; Git Bash only runs git
Answer

Unix-style commands like ls and mkdir -p, because the shell is Bash. The window does not decide the commands; the shell does. A Bash tab speaks Bash even inside Windows Terminal.

Open this step in lesson mode · Link to this step · This confused me

15Cheat sheet

Keep this nearby until the commands feel familiar.

Reference Terminal cheat sheet: PowerShell and zsh
TaskPowerShellmacOS zsh
Where am Ipwdpwd
Listls, ls -Force for hiddenls, ls -a for hidden
Movecd folder, cd .., cd ~same
Make foldersmkdir a\b\cmkdir -p a/b/c
Make an empty fileNew-Item f.txttouch f.txt
Print a filecat f.txtcat f.txt
Delete (no undo)Remove-Item f.txt, -Recurse for foldersrm f.txt, rm -r for folders
Show PATH$env:Path -split ';'echo $PATH | tr ':' '\n'
Last exit code$LASTEXITCODE (programs) or $? (PowerShell commands)echo $?
Stop a programCtrl + CControl + C
Clear the screenclear or clsclear

Put these in order to create a folder called notes inside your Code folder and check it worked, starting from anywhere.

  1. cd Code
  2. cd ~
  3. ls
  4. mkdir notes
Answer

1. cd ~ 2. cd Code 3. mkdir notes 4. ls. Go home first so the relative path is predictable, step into Code, make the folder, then list to confirm.

Open this step in lesson mode · Link to this step · This confused me

16Challenges

Level 2, Builder

Challenge

Build the skeleton of Beacon Yard's folder tree using only the terminal, starting from your home folder. Use the sandbox below, so nothing touches your real beacon-yard later.

Start from
The terminal sandbox, preset home, in either flavour.

Done means

  • Code/beacon-yard/src/server, src/shared and src/client all exist.
  • An empty file README.md exists in Code/beacon-yard.
  • You used tab completion at least once (the Sim checks history for a completed path).
  • Your current directory at the end is Code/beacon-yard.

Hints

  1. On zsh, mkdir needs -p to create nested folders in one go.
  2. Create the three folders from inside src to keep the paths short.
  3. Use cd .. to climb back to beacon-yard.
Solution
luau
zsh: cd ~/Code; mkdir -p beacon-yard/src; cd beacon-yard/src; mkdir server shared client; cd ..; touch README.md. PowerShell: cd ~\\Code; mkdir beacon-yard\\src; cd beacon-yard\\src; mkdir server, shared, client; cd ..; New-Item README.md

The terminal sandbox

The terminal sandbox: a still of the simulation
Figure 16.1.

Level 1, Apprentice

Challenge

Repeat the idea in your real terminal, with no sandbox: make a folder, look at it and read the exit code.

Start from
Your real terminal, in your home folder.

Done means

  • You created Code/practice in your real Code folder using the terminal.
  • You listed Code and saw practice in the output.
  • You printed the exit code of your last command and it was 0 (or True for $? in PowerShell).

Hints

  1. mkdir accepts a relative path: mkdir Code/practice works from your home folder on both systems.

Open this step in lesson mode · Link to this step · This confused me

17Recap

Retiring the analogy

You no longer need “the workshop's tool counter, where a clerk does one ordered thing and reports back”. A shell reads a line, finds the program by name in PATH, runs it with the arguments in the current directory, and reports its exit status. It never asks for confirmation unless the program does.

Recap

  1. The prompt shows where you stand. pwd, ls and cd answer where am I, what is here, and go there; Tab and the Up arrow do most of the typing.
  2. Programs are found through PATH, a list of folders. A terminal opened before an install does not see the new PATH, so open a fresh one.
  3. Exit code 0 means success and anything else means failure, which is what CI reads. Ctrl + C stops a running program, and terminal deletes have no undo.

The terminal is the workshop's tool counter, where a clerk does one ordered thing and reports back, until a real clerk asks 'are you sure?' and keeps returns, but the terminal does exactly what you typed: deletions skip the Recycle Bin and there is no undo.

Next A code editor from zero: VS Code and Cursor

Open this step in lesson mode · Link to this step · This confused me