Step 01 of 10

The command line

Open a terminal, move around your files, create and delete folders, and run programs by typing commands.

14 min 9 sections

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:

text
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:

bash
pwd

type 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.

bash
pwd
text
/Users/ana

pwd 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:

bash
ls
text
Desktop    Documents    Downloads    Music    Pictures

Many 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.

bash
ls -la

Moving around

cd means "change directory":

bash
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 home

Everything 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, then Documents/notes.txt means 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:

bash
cd ~
mkdir code                 # make directory
cd code
mkdir -p projects/hello    # -p creates the parent folders too, if needed

Create an empty file and see its contents:

bash
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:

bash
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 = rename

Delete:

bash
rm todo.txt                 # delete a file
rm -r projects/hello        # delete a folder and everything inside it

Names 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:

bash
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:

bash
python3 --version

The pattern is always program, options, arguments:

text
cp        -r          photos    photos-backup
program   option      argument  argument

To 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

TaskmacOS / LinuxPowerShell
Where am I?pwdpwd
List filesls, ls -lals, ls -Force
Change foldercd folder, cd .., cd ~same
Make a foldermkdir name, mkdir -p a/bmkdir name (creates parents automatically)
Create an empty filetouch file.txtNew-Item file.txt
Show a filecat file.txtcat file.txt
Copycp a b, cp -r dir1 dir2cp a b, cp -r dir1 dir2
Move or renamemv a bmv a b
Deleterm file, rm -r folderrm file, rm -r folder
Clear the screenclear (or Ctrl+L)clear

Practice

Using only the terminal:

  1. Go to your home folder and create this structure:

    text
    code/
      practice/
        notes/
          ideas.txt
        archive/
  2. Copy ideas.txt to archive/ideas-old.txt.

  3. Rename notes/ideas.txt to notes/plans.txt.

  4. List everything inside practice, including subfolders. (Hint: ls -R on macOS and Linux, ls -Recurse in PowerShell.)

  5. Delete the archive folder and everything in it.

  6. Without using cd, list the contents of notes from your home folder using a relative path.

Show solution
bash
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/notes

ls -R prints:

text
archive	notes

./archive:
ideas-old.txt

./notes:
plans.txt

mkdir -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, ls and cd tell you where you are, what's there and move you around; . is here and .. is the parent.
  • mkdir, touch, cp, mv and rm create, copy, move, rename and delete; rm is permanent.
  • Tab completes names, the up arrow repeats commands, and Ctrl+C stops what's running.
  • When something fails, read the message, check pwd and ls, and avoid spaces in file names.

Check yourself

Quiz

0/4 correct · 4 left

  1. 1.You're in /Users/ana/code. Which path refers to /Users/ana/Downloads?

  2. 2.What does mv report.txt final-report.txt do?

  3. 3.Why does cd My Documents fail?

  4. 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.