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:
and on MacOS you can use the Finder:
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:
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.
Navigating the file system
On Windows, the file system is organized as a set of trees:
On MacOS, it looks like this:
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 directoryls
— list folders and files in the current directorycd
— 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:
And on MacoS it will look like this:
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:
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:
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:
Notice you have two more directories here — hello
and intro
. Now cd
into
the hello
directory and use ls
to see what is there:
Now you can see the hello.py
program. You can run it like this:
python hello.py
You should see the program run:
You should be able to do the following to run the other program that came with Lab 0:
cd ..
cd intro
python introduce-yourself.py
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
.