Skip to content

Week 1 · Python and your developer toolkit

The terminal

What the terminal is, the commands you'll use every day, and how to run a Python file.

ConceptEstimated time: 30 min

The terminal is a text window where you control your computer by typing commands instead of clicking. Engineers use it because it's fast, it can be repeated and automated, and most developer tools, including Python, Git and every deployment tool you'll meet, are built to be used from it.

Open it now and follow along: Terminal on macOS, Ubuntu on Windows. Every command on this page works the same on both.

The prompt

When the terminal is ready for a command, it shows a prompt, ending in $ or %. You type a command after it and press Enter. In this course, code blocks show only the command, without the prompt:

whoami

That prints your username. If the terminal prints nothing after a command, that usually means it worked: no news is good news.

Where am I? Folders and paths

Your files live in folders (also called directories), inside other folders. The terminal is always "standing" in one folder, called the current directory.

CommandWhat it does
pwdPrint working directory: shows where you are
lsList the files and folders here
ls -aList everything, including hidden files that start with a dot
cd projectsChange directory: move into the projects folder
cd ..Move up one level, to the parent folder
cd ~Go to your home folder (~ is short for it)

A path describes where a file is. ~/projects/fde-course/hello.py means: start in your home folder, go into projects, then fde-course, and find hello.py.

Creating and managing files

CommandWhat it does
mkdir projectsMake a new directory called projects
mkdir -p projects/fde-courseMake a folder and any missing parent folders in one go
touch notes.txtCreate an empty file
cat notes.txtPrint a file's contents
cp notes.txt backup.txtCopy a file
mv notes.txt ideas.txtMove or rename a file
rm ideas.txtRemove (delete) a file

Running Python from the terminal

There are two ways to run Python:

  1. Interactively. Type python3 to start the interpreter, try lines one at a time, and type exit() to leave. Good for quick experiments.

  2. As a script. Save your code in a file ending in .py and run the whole file:

    python3 hello.py
    

    This is how you'll run almost everything in the program.

To open the current folder in VS Code, run:

code .

The . means "this folder".

Time-savers

  • Tab completes file and folder names. Type cd proj and press Tab.
  • ↑ brings back your previous commands, so you don't have to retype them.
  • Ctrl C stops a program that's running or stuck. It's not copy in the terminal.
  • clear clears the screen.

Reading error messages

When something goes wrong, the terminal tells you. Read the message before doing anything else: it's usually telling you exactly what's wrong.

MessageWhat it means
command not foundYou mistyped the command, or the tool isn't installed
No such file or directoryThe file or folder isn't where you said. Check with pwd and ls
Permission deniedYou're not allowed to change that file or folder

Finished this lesson?