The terminal (Mac and Windows)
The super-short guide to the terminal
The classical way to use a computer is through a command-line window, often called a terminal. Using the keyboard, one writes commands that the computer will understand and execute. Since graphical user-interfaces (GUIs) are now the dominating way to use computers, many people have never used or even seen a command-line interface. The terminal has the obvious disadvantage that the user must remember a large number of commands, while in a GUI system the available programs and commands are typically visible as icons or in menus. However, if one gets past the first threshold of memorizing a few commands, the terminal is a very efficient way to use a computer.
This guide is very incomplete, but includes the most important commands for navigating directories and running python programs. Enough to get you started, but in the longer term you want to consult a more complete guide such as this one or this one.
Opening the terminal
- Mac: The program “Terminal” can be found in the directory Applications/Utilities (or by searching with Command-Space)
- Windows: If you have installed Python from Anaconda, you should have a program named "Anaconda Powershell" visible in the "Anaconda Navigator" window. This will open a terminal which is very similar to the Unix-style terminal found on Mac and Linux. It is also possible to open a Windows-native Powershell from the Start menu, but this will sometimes struggle to find Python and the required packages. We recommend to use the "Anaconda Powershell".
- Linux: There are many different Linux versions, but searching for “terminal” should get you the right application.
The five commands you absolutely need to know
In IN1900 we will mostly use the terminal window to run our Python programs. For this purpose, we need to be able to do the following tasks:
- Check the contents of a the directory you are in. On Mac, Linux, and Powershell, the
command is
ls
. (In the old style Windows/DOS command-line window the command isdir
.) - Move to another directory. For this we use
cd
. Simply typingcd
with no arguments will send you to your home directory. Typingcd mydir
will move you inside the directory namedmydir
. The directory you are in has name the name.
, while..
is the directory above the one you are in. To move one level up in the directory tree, the command iscd ..
- Copy a file, using
cp
. Typingcp file1 file2
will make a copy offile1
with the namefile2
. Similarlycp file1 mydir/file2
will create a copy offile1
in the directorymydir
(given that the directory exists) - Delete a file with
rm
. Typingrm file1
will removefile1
immediately and permanently (Without the Windows-style dialogue asking Are you sure you want to delete this file... . - Creating a directory with
mkdir
. Typingmkdir mydir
will create the directorymydir
as a sub-directory of the directory you are in.
In addition to these five basic commands, we need to run Python
programs, by typing python myprogram.py
when you are located in the
directory where you saved the program myprogram.py
. (If you are inside
an iPython window, the correct command is run myprogram.py
.)