Step 01 of 10
The command line
Open a terminal, move around your files, create and delete folders, and run programs by typing commands.
Programmers spend a lot of time in a window full of text called the terminal. It looks old-fashioned, but it's the fastest way to run programs, install tools and work with files, and nearly every tutorial, tool and job assumes you can use it. This lesson teaches the dozen commands you'll use every day. You don't need to memorise anything: you'll use these so often that they'll stick on their own.
Opening a terminal
The terminal is a program that runs a shell: a program that waits for you to type a command, runs it, and prints the result.
- macOS: open Terminal (press Cmd+Space, type "Terminal", press Enter). The shell is called zsh.
- Linux: open Terminal from your applications menu, or press Ctrl+Alt+T on many distributions. The shell is usually bash.
- Windows: open Windows Terminal or PowerShell from the Start menu. The commands in this lesson work in PowerShell too, with the differences noted along the way.
You'll see a prompt, something like:
ana@laptop ~ %It shows your username, your computer's name and where you are (~ means your home folder). The prompt is the shell saying "I'm ready". In this course, commands are shown without the prompt, so when you see:
pwdtype pwd and press Enter.
Where am I? Folders and paths
Your files are organised in folders (also called directories) inside other folders, like a tree. The shell is always "in" one folder, called the current directory or working directory.
pwd/Users/anapwd means "print working directory". The answer is a path: the route from the top of the tree (/, called the root) down to where you are. On Windows paths look like C:\Users\ana, with backslashes.
To see what's in the current folder, list it:
lsDesktop Documents Downloads Music PicturesMany commands accept options (also called flags) that change what they do. ls -l shows a long listing with sizes and dates; ls -a shows hidden files, whose names start with a dot.
ls -laMoving around
cd means "change directory":
cd Documents # go into the Documents folder
pwd # /Users/ana/Documents
cd .. # go up one level, to the parent folder
cd ~ # go to your home folder from anywhere
cd # on macOS and Linux, plain cd also goes homeEverything after # is a comment: a note for humans that the shell ignores. You don't need to type the comments.
There are two kinds of path:
- An absolute path starts at the root and works from anywhere:
/Users/ana/Documents/notes.txt. - A relative path starts from where you are now: if you're in
/Users/ana, thenDocuments/notes.txtmeans the same file.
Two special names help with relative paths: . means "this folder" and .. means "the parent folder". So ../Downloads means "go up one level, then into Downloads".
Press the up arrow to bring back previous commands. Press Ctrl+C to stop a command that's running (or to abandon a line you're typing). These three keys will save you hours.
Creating, copying, moving and deleting
Make a folder for your coding work:
cd ~
mkdir code # make directory
cd code
mkdir -p projects/hello # -p creates the parent folders too, if neededCreate an empty file and see its contents:
touch notes.txt # create an empty file (PowerShell: New-Item notes.txt)
cat notes.txt # print a file's contents (empty for now)Copy, move and rename:
cp notes.txt notes-backup.txt # copy
mv notes-backup.txt projects/ # move into a folder
mv notes.txt todo.txt # "move" to a new name = renameDelete:
rm todo.txt # delete a file
rm -r projects/hello # delete a folder and everything inside itNames with spaces
The shell splits commands on spaces, so cd My Projects means "cd with two arguments: My and Projects", which fails. Wrap names with spaces in quotes:
cd "My Projects"This is why programmers usually name files and folders without spaces, using dashes or underscores: my-projects, budget_2026.csv.
Running programs
Every command you've typed is a program. ls is a small program stored somewhere on your computer, and the shell finds it by name. When you install Python in the next lesson, you'll run it the same way:
python3 --versionThe pattern is always program, options, arguments:
cp -r photos photos-backup
program option argument argumentTo learn what a command can do, ask it. Most programs print help with --help, and on macOS and Linux man ls opens the full manual (press q to quit, space to page down).
When a command fails, read the message. "No such file or directory" means the path is wrong: check your current folder with pwd and look at what's there with ls. "Permission denied" means you're not allowed to change that file. "command not found" means the program isn't installed, or the name is misspelled.
A reference card
| Task | macOS / Linux | PowerShell |
|---|---|---|
| Where am I? | pwd | pwd |
| List files | ls, ls -la | ls, ls -Force |
| Change folder | cd folder, cd .., cd ~ | same |
| Make a folder | mkdir name, mkdir -p a/b | mkdir name (creates parents automatically) |
| Create an empty file | touch file.txt | New-Item file.txt |
| Show a file | cat file.txt | cat file.txt |
| Copy | cp a b, cp -r dir1 dir2 | cp a b, cp -r dir1 dir2 |
| Move or rename | mv a b | mv a b |
| Delete | rm file, rm -r folder | rm file, rm -r folder |
| Clear the screen | clear (or Ctrl+L) | clear |
Practice
Using only the terminal:
Go to your home folder and create this structure:
text code/ practice/ notes/ ideas.txt archive/Copy
ideas.txttoarchive/ideas-old.txt.Rename
notes/ideas.txttonotes/plans.txt.List everything inside
practice, including subfolders. (Hint:ls -Ron macOS and Linux,ls -Recursein PowerShell.)Delete the
archivefolder and everything in it.Without using
cd, list the contents ofnotesfrom your home folder using a relative path.
Show solution
cd ~
mkdir -p code/practice/notes code/practice/archive
cd code/practice
touch notes/ideas.txt # PowerShell: New-Item notes/ideas.txt
cp notes/ideas.txt archive/ideas-old.txt
mv notes/ideas.txt notes/plans.txt
ls -R # PowerShell: ls -Recurse
rm -r archive
cd ~
ls code/practice/notesls -R prints:
archive notes
./archive:
ideas-old.txt
./notes:
plans.txtmkdir -p accepts several paths at once and creates any missing parents, so one command builds both branches of the tree. The final ls code/practice/notes works from your home folder because the path is relative to where you are; from anywhere else, you'd use the absolute path or ~/code/practice/notes.
Key takeaways
- The terminal runs a shell, which runs the commands you type: program, then options, then arguments.
pwd,lsandcdtell you where you are, what's there and move you around;.is here and..is the parent.mkdir,touch,cp,mvandrmcreate, copy, move, rename and delete;rmis permanent.- Tab completes names, the up arrow repeats commands, and Ctrl+C stops what's running.
- When something fails, read the message, check
pwdandls, and avoid spaces in file names.
Check yourself
Quiz
0/4 correct · 4 left
1.You're in /Users/ana/code. Which path refers to /Users/ana/Downloads?
2.What does mv report.txt final-report.txt do?
3.Why does cd My Documents fail?
4.You ran rm -r old-project by mistake. How do you get it back?
Finished reading?
Mark it complete to fill in your roadmap.