This reference will give you a simple primer on some basic Terminal commands. These commands should work on any Mac or Linux computer. (Windows uses a different system.) More information can be found at the MIT Missing Semester webpage or at a Wellesley Missing Semester Workshop.
Instructions can be given to the computer by using the following format (where some commands have 0 arguments, others have 1, etc.):
command argument1 argument2...
cd - (Change Directory) moves you to a different location within the file structure. Works with both absolute and relative paths. (An absolute path is one that starts at a particular location (usually root or home). A relative path generally starts from your current location.) Different levels of the path are separated with slashes.
cd .. - moves you to the parent directory of your current location.
cp - (CoPy) creates a copy of the referenced file or directory (first argument) and puts it in a new location (second argument).
ls - (LiSt directory contents) shows you all the (visible) files and folders in your current directory.
ls -a - the a flag here tells the command to also show "hidden" files and folders. Hidden files/folders begin with .. (This should not be confused with the location ., which stands on its own.)
man - (MANual) this command brings up the "manual" page for any command in the system. You can also find "man pages" online by searching the web. These pages contain descriptions of what the command does as well as what flags/arguments are available to use.
mkdir - (MaKe new DIRectory) creates a new folder (either in the current location or at the path given).
mv - (MoVe) moves the file/folder specified (first argument) to the location given (second argument).
pwd - (Print Working Directory) gives the absolute path (from root) to your current location.
rm - (ReMove) removes the specified file. Be careful when using it as it is irreversible. (Unlike moving an item to the Trash in a GUI desktop, you cannot recover an item that has been removed via commandline.)
rm -r - the r flag here tells the command to remove recursively (ie go into each directory and also remove its contents). You must use the r flag to remove a directory. (There's a famous story about an errant rm -r * command during the production of Toy Story 2.)
touch - can be used to create a new file without opening a text editor. Can also be used to modify permissions and metadata on a file.
. (on its own) means "here".
.. means "the parent directory of ."
/ on its own means "root". Root is the start of your file tree. Everything on the computer can be gotten to via a path that starts at root. / is also used to write multi-step paths. (eg ~/Desktop/Homework )
~ means "home". Home is the directory that contains your user account. Generally, you'll work within the home subsection of the file tree. By default, a new Terminal should open with you at home.
* is the wildcard symbol. It represents all possible strings.
|, >, and < are redirection operators. They allow you to take the output from a one command/location and redirect it somewhere else.
| (pipe) takes the output from one command and makes it the input to another command
> takes the output from a command which would usually go to the standard output and allows you to redirect it to a file. (>> appends instead of ovewriting the file.)
< takes the contents of a file and sends it to a command.
If you want to edit text on the commandline, you can do so with a text editor. The most commonly used are emacs and vim. (You may also occasionally see nano.) Each has their own quirks. Most computer scientists have a favorite. Often commandlines will default to emacs, which is more powerful but (IMO) less intuitive than vim. It can be helpful to look up a reference document for the keyboard shortcuts for whichever text editor you're using.
Vim Commands:
(open vim with the file name as the first argument)
i will put you in "Insert" mode
Esc (the key, not the letters) will get you out of insert mode
:wq will give vim the commands to Write and Quit (save/quit)
if you get stuck in Vim with the wrong file open (or other problem) you can use :q! to quit without saving
cat - (conCATenate) sends the contents of one or more files (or other forms of data) to standard output to be read.
clear - clears the commandline window so all that's left is a single new command prompt at the top. Very helpful if you've got a long swath of text and are having trouble keeping track of where you are. (In the Mac Terminal, you can still scroll up to see what you cleared away.)
grep - (Global/RegularExpression/Print) is your go-to text search tool. grep looks for a "search pattern" (often in the form of a regular expression) in one or more files or locations.
echo - writes the arguments given to standard output
less - displays the contents of a file in the terminal in a scrollable way (not directly in standard output)
python (or python3) - opens a python interpreter (basically, the shell from Thonny). It can be called without any arguments or with argument(s) of python files to run. You can also run files from within the python interpreter. (You can use which to determine whether python is connected to a version of python 2 or python 3 and therefore whether you need to use the python3 command.)
which - used with any other command/application, it gives you the absolute path to that tool (thus explaining which version is being used by default)