Lesson 1 of 6
The terminal: pwd, ls, cd
The terminal is a window where you type instructions instead of clicking. It looks old-fashioned, but it's how almost every programming tool works, including the AI ones. You only need three commands to start: pwd, ls and cd.
Open a terminal
| Computer | How to open it |
|---|---|
| Mac | Press ⌘ Space, type Terminal, press Return. |
| Windows | Press the Start key, type Terminal (or PowerShell), press Enter. |
| Linux | Usually Ctrl Alt T. |
You'll see a line ending in $ or % or > and a blinking cursor. That line is the prompt: the computer waiting for you. Type a command, press Enter, read what comes back. That's the whole loop.
Practice on this one first
This desk computer runs a pretend terminal with the same folders as the filing cabinet in the Preliminaries. Click it and type, or tap the command buttons. Nothing you do here can break anything.
pwd: where am I?
Print working directory. It prints the absolute path of the folder you're standing in.
$ pwd /Users/you
When a terminal opens, you start in your home folder (~).
ls: what's here?
List. It shows the files and folders in the folder you're standing in.
$ ls Desktop Documents Downloads Music Pictures
Add -la for the long version: one line per item, with sizes in bytes, dates, and hidden files whose names start with a dot (like .gitignore).
$ ls -la drwxr-xr-x 5 you staff 160 Oct 28 09:12 . -rw-r--r-- 1 you staff 29 Oct 28 09:12 hello.js drwxr-xr-x 3 you staff 96 Oct 28 09:10 photos
A line that starts with d is a directory (folder). The number before the date is the size in bytes: hello.js is 29 bytes, exactly the count you saw in the Preliminaries.
cd: go somewhere
Change directory. You give it a path, absolute or relative, and the terminal moves there.
$ cd Documents $ pwd /Users/you/Documents $ cd .. $ pwd /Users/you
| You type | You go to |
|---|---|
cd code | The code folder inside where you are now |
cd .. | Up one level, to the folder that contains this one |
cd ~ or just cd | Home, from anywhere |
cd / | The very top of the disk |
cd - | Back to the folder you were in before |
cd Doc and press Tab. ↑ brings back your last command so you can run it again or edit it.Make things: mkdir and touch
Two more and you can set up a project without touching the mouse.
$ mkdir my-site $ cd my-site $ touch index.html $ ls index.html
mkdir makes a directory. touch makes an empty file (zero bytes) if it doesn't exist yet. On Windows PowerShell, pwd, ls, cd and mkdir all work the same way; instead of touch, use ni index.html (short for New-Item).
rm (remove) in tutorials and AI suggestions. It deletes files for good: there's no Trash. Read any rm command twice, and never run one you don't understand, especially with -rf in it.Predict the output
Reading a terminal is mostly predicting what happens next. Try these without the figure, then check yourself on the desk computer above.
Your real terminal, for real
Do this once on your own computer. It makes the folder you'll use for the rest of the path.
$ cd ~ $ mkdir hello $ cd hello $ pwd
Then open that folder in your file browser (on a Mac: open ., on Windows: explorer ., the dot means “this folder”) and see that the terminal and the windows you click on are looking at the same place.
- The terminal always stands in one folder.
pwdtells you which. lslists what's there.cd namegoes in,cd ..goes up,cd ~goes home.mkdirmakes a folder,touchmakes an empty file.- Tab completes names. ↑ repeats. Read
rmtwice.