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

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:

  1. 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 is dir.)
  2. Move to another directory. For this we use cd. Simply typing cd with no arguments will send you to your home directory. Typing cd mydir will move you inside the directory named mydir. 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 is cd ..
  3. Copy a file, using cp. Typing cp file1 file2 will make a copy of file1 with the name file2. Similarly cp file1 mydir/file2 will create a copy of file1 in the directory mydir (given that the directory exists)
  4. Delete a file with rm. Typing rm file1 will remove file1 immediately and permanently (Without the Windows-style dialogue asking Are you sure you want to delete this file... .
  5. Creating a directory with mkdir. Typing mkdir mydir will create the directory mydir 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.)