Your System's Terminal
If you think about how you usually use a computer, you probably navigate to a file by clicking on folders (also called directories) and open a program or file by double clicking on them. When you are programming on a computer, you often need to run programs and send them options, called arguments, which is nearly impossible to do with only a click.
Because of this, every operating system contains a Command Line Interface (CLI) that lets you interact with your computer using a keyboard known as a terminal. You can do everything you already do on a computer via the terminal, but you can also do a whole lot more!
Windows: Opening Command Prompt
- On your keyboard, press
[Windows Key]
to bring up the "Start" menu - Without clicking anything, type
cmd
and this will show you the "Command Prompt" app - Run the Command Prompt by pressing
[Enter]
(or clicking it) - The black box is the Windows Terminal and you will run commands by typing in that terminal
MacOS: Opening Terminal
- On your keyboard, press
[Command] + [Space]
to open Spotlight - Type
Terminal
and then[Enter]
to launch the Terminal app - The white (or black if you're on dark mode!) box is the Terminal and you will run commands by typing in that terminal
The Terminal Prompt
All terminals start every line with a prompt that shows the current working directory of the terminal. By default, both Windows and Mac start you off in the base folder for your user account. The syntax varies only slightly between the two (assuming a user named Wade), so the initial prompt should be one of the following:
- Windows:
C:\Users\Wade\>
- MacOS:
Wades-MacBook-Pro:~ Wade$
Current working directory
When using the terminal, you are always "inside" of one specific folder (much like when you double-click a folder you see the contents of everything in that folder and only that folder). The current folder that your terminal is in is referred to as the "current working directory".
In Data Science DISCOVERY, we recommend that you work within a directory called stat107
on your desktop. If you haven't already, make sure to create a folder on your Desktop called stat107
.
In order to navigate to that folder (or directory), we need to first navigate to your Desktop and then navigate to the stat107
directory. Both of these things can be done with the cd
command (cd for "change directory"):
cd Desktop
cd stat107
The above commands will move you from your "home" directory, into your desktop, and then into the stat107
folder. If you get no errors when you run the above commands, you have successfully navigated to your stat107
directory! Your terminal prompt should now show:
- Windows:
C:\Users\Wade\Desktop\stat107>
- MacOS:
Wades-MacBook-Pro:stat107 Wade$
Common Alternative Location on Windows: OneDrive
If you enabled OneDrive backup for your desktop when you set up your computer, your Desktop folder is likely inside of your OneDrive folder. To find your Desktop, you will need to first navigate into OneDrive:
cd OneDrive
cd Desktop
cd stat107
Make sure that your prompt ends with stat107 before you continue (ex: C:\Users\Wade\OneDrive\Desktop\stat107>
).
Useful Command: Listing Files
When using the terminal, you often want to know what files are in your current folder or current working directory. To list all files in the current directory:
- Windows:
dir
- MacOS:
ls
Useful Command: Moving Up a Folder
In addition to moving "forward" or "deeper" into your directories, the special cd ..
will change your directory "up" one directory.
- Moves into
stat107
from your Desktop (one level deeper):cd stat107
- Moves back to your Desktop from
stat107
(one level shallower):cd ..