BYU logo Computer Science

Using the terminal

If you have a Windows computer use the guide for the Windows terminal setup to configure your system.

Normally, you will interact with your computer using a visual interface. For example, on Windows, you can use the File Explorer:

file explorer window

and on MacOS you can use the Finder:

finder window

Developers will often use a terminal to access the files on their computer. A terminal is a textual interface to all of the same directories and files that you can see visually.

Opening the terminal in PyCharm

In PyCharm you can access the terminal by clicking the Terminal tab at the bottom:

accessing the terminal in PyCharm by clicking the Terminal tab

The terminal is opened on the bottom by default. If you are using Windows, your prompt will look like this, ending with a >:

(venv) PS C:\Users\zappala\Documents\cs110>

If you are using MacOS, your prompt will look like this, ending with a %:

zappala@copenhagen cs110 %

Your prompt is where you can type commands in the terminal. After you type a command, you will see a response below your command, with a new prompt.

On Windows, the file system is organized as a set of trees:

a tree of files, starting with root (C:) and going down to Program Files, Users, and other folders, and then C:\Users\zappala, C:\Users\zappala\Documents, and so forth

On MacOS, it looks like this:

a tree of files, starting with root (/) and going down to Applications, Users, and other folders, and then /User/zappala, /User/zappala/Documents, and so forth

Each icon shown in these diagrams is a directory. Directories contain files.

There are several basic commands that will let you navigate and view your file system:

  • pwd — print the name of the current directory
  • ls — list folders and files in the current directory
  • cd — change directory

When you open the terminal from inside PyCharm, you are placed inside the directory for your project. If you created a single project for CS 110 in a cs110 folder, then you are in that folder, e.g. C:\Users\zappala\Documents\cs110>.

The pwd command

Type the pwd command at the prompt and you will see the current directory. On Windows it will look like this:

running the pwd command in powershell

And on MacoS it will look like this:

running the pwd command in zsh

You may notice that your prompt will also show you your current directory, so you may not need to use this command often, but it can be helpful if you are confused.

The ls command

Type the ls command at the prompt to list the directories and files in the current directory:

running the ls command in the terminal

If you are starting out in your cs110 directory, you will probably see the directories for all of the labs, homeworks, and projects you have done so far.

The cd command

Type the following command:

cd lab0

This command mvoes you into the lab0 directory:

running cd lab0

Notice how the prompt in the terminal changes to reflect the fact that you are now in the lab directory. You can type ls to see what files are there.

Now type:

cd ..

This will go back to the parent direcotry, which in this case should be cs110, the directory we were previously in. You can type ls again to see the files here again.

Notice how cd essentially moves you down to a child directory or up to the parent directory.

Running python programs

If you are in the same directory as a program, you can run it. You should have a lab0 directory, but if not, you can download the zip file for lab0.

First, cd into the lab0 directory and use ls to list what is there:

running cd lab0 and then ls

Notice you have two more directories here — hello and intro. Now cd into the hello directory and use ls to see what is there:

running cd hello and then ls

Now you can see the program. You can run it like this:


You should see the program run:

running python

You should be able to do the following to run the other program that came with Lab 0:

cd ..
cd intro

running the above commands

The exit command

You can exit out of a terminal using the exit command. Any time you use exit, the next time you open the terminal you will be back at the main directory for your project, which should be cs110.