Terminal#

Video Tutorial

Opening a terminal#

Each operating system opens terminals in a different way.

Search for powershell in the Windows taskbar search or press Win+R buttons (simultaneously), then type powershell in the small run window appearing, press Enter.

This should open a Terminal looking something like this:

../_images/terminal.gif

Open the Launchpad icon in the Dock, or press Command+Space; type Terminal and click on it.

See more detailed explanation here.

This should open a Terminal looking something like this:

../_images/terminal1.gif

Opening Python in a Terminal#

To launch Python using the Terminal, you can use python.

This should look something like this in your Terminal:

../_images/openPython.gif

To launch Python using the Terminal, you can use python3.

This should look something like this in your Terminal:

../_images/openPython1.gif

Exiting Python in a Terminal#

To exit Python in your Terminal you can use exit()

This should look something like this in your Terminal:

../_images/exitPython.gif

To check which Python version you have you can use python3 --version

Note that this might change depending whether you have more than one Python version installed

To exit Python in your Terminal you can use exit()

This should look something like this in your Terminal:

../_images/exitPython1.gif

Running a Python script in the Terminal#

To run a Python script using the terminal, you can use python + space + absolute path of your script.

For example, if you wanted to run a script that has the absolute path C:\Users\python\test\helloWorld.py containing only the line print("Hello World"), this should look something like this in your Terminal:

../_images/runPython.gif

To run a Python script using the terminal, you can use python3 + space + absolute path of your script.

For example, if you wanted to run a script that has the absolute path /Users/yourname/Desktop/helloWorld.py containing only the line print("Hello World"), this should look something like this in your Terminal:

../_images/runPython1.gif

Printing Working Directory#

Use the command pwd to print your current working directory. This tells you where in your file system, the terminal is operating.

../_images/pwd.gif

Use the command pwd to print your current working directory. This tells you where in your file system, the terminal is operating.

../_images/pwd1.gif

Seeing What is in a Directory#

Use the command ls to print everything in the current working directory

../_images/ls.gif

Use the command ls to print everything in the current working directory

../_images/ls1.gif

Changing Directories#

The command cd can be used to change your directory. For example one could write cd MyFolder in order to move to the folder named MyFolder The command cd .. can be used to move backwards by one directory.

../_images/cd.gif

The command cd can be used to change your directory. For example one could write cd MyFolder in order to move to the a folder named MyFolder The command cd .. can be used to move backwards by one directory

../_images/cd1.gif

Creating a Folder#

Use mkdir followed by the desired name of a new folder to create a new folder in the current working directory. For example mkdir NewPythonFolder will create a new folder with the name NewPythonFolder in the current working directory

../_images/mkdir.gif

Use mkdir followed by the desired name of a new folder to create a new folder in the current working directory. For example mkdir NewPythonFolder will create a new folder with the name NewPythonFolder in the current working directory

../_images/mkdir1.gif

Removing a Folder#

rm -r followed by a folder name, will remove the given folder.
For example rm -r NewPythonFolder will remove the folder named NewPythonFolder
../_images/rm.gif
rm -r followed by a folder name, will remove the given folder.
For example rm -r NewPythonFolder will remove the folder named NewPythonFolder
../_images/rm1.gif

Clearing output#

clear will clear all output from the terminal

clear will clear all output from the terminal