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: In Windows 10, you have two options. The first is the “Command Prompt”, which is the classical Windows/DOS command line interface, and the second is the “Windows Powershell”. Both can be opened from the start menu. The “Windows Powershell” is very similar to the Unix-style shell found on Mac and Linux, while the “Command Prompt” has a more Windows-specific set of commands. Older versions of Windows will probably only have the “Command Prompt”.
- 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 Unix, the command is ls, while in the Windows/DOS command-line window the command is dir.
- 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.
- 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)
- 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... .
- 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.)