Command Line Basics

The command line is a text-based interface for interacting with your computer. From the command line you can launch programs, view files, and manipulate your file system by making, moving, and copying files and directories. You can think of it as the Finder in Mac, without the graphic interface, but much more powerful.

Setup

  • On a Mac you can access the command line by opening up the Terminal application, located in /Applications/Utilities/Terminal
  • On Windows follow the instructions to install git below and then use the gitbash to access the terminal.

The Prompt

When you open up your terminal application you’ll see something like this:

SamsComputer:~ sam$

This is called the “prompt”. By default (on a Mac) it shows the name of the computer, the directory that you are currently in, your username, and then a $ sign.

The basic use of the command line is: 1) you type a command, 2) you hit return, and 3) some output of the command is printed to the screen.

Basic Navigation & File Operations

Please note I use the word “directory” and “folder” interchangeably.

When you open a new terminal window, you are placed inside your home folder. On a Mac this is /Users/myusername and on Linux, /home/myusername.

To see the folder you are currently in, type: pwd and hit return. pwd stands for “print working directory”, or in other words, “show me the directory I am currently working from”.

Here are some basic commands for getting around, making, deleting and copying files and folders.

pwd stands for “print working directory”. It prints out where you are:

pwd

ls stands for “list”. It lists the contents of current directory.

ls

cd stands for “change directory”. Type cd and then the directory you want to go to. For example, change to the Desktop from your home folder:

cd Desktop

To go into the parent folder, up one level in the file structure, type .. or ../ instead of a folder name, like so:

cd ..

If you type cd without a folder name after, it takes you back to your home folder.

mkdir stands for “make directory”. Type mkdir and then a name to make a folder. For example, make a folder called “cool_project”:

mkdir cool_project

mv stands for “move”. It lets you move files and folders and also rename them. To rename a file:

mv oldname.txt newname.txt

cp stands for “copy”. It lets duplicate files:

cp draft.txt draft_copy.txt

rm stands for “remove”. It lets you delete files:

rm bad_selfie.jpg

Please note, rm will not ask for confirmation, and it will not move files to the trash. It’ll just delete them immediately, so be careful.

Running a local server:

cd into the folder where you want to run the server. This should be where your p5 files are stored.

Check what version of python you are running by typing python -v into the terminal.

If python 2.7:

python -m SimpleHTTPServer 8000

If python 3:

python3 -m http.server 8000

You should then see

Serving HTTP on 0.0.0.0 port 8000 ...

This means the server is up and running at localhost on port 8000. And this means you can type http://localhost:8000/ into the address of a web browser and I’ll see:

Running a local server on Windows

Windows will require you to install Python to get a server set up. Follow the download and installation instructions here for Python 2.7.X. 

  • You will also need to make sure that Git Bash recognizes python. You can do this temporarily with this command in Git Bash: PATH=$PATH:/c/Python36/ (or whatever version of python you are running). However if you want this to be permanent you’ll need to add c:\python36 to your system environment variable pathHere is how you access that.