Week 2 · Session 1

The Terminal and the File System

Moving around your computer by typing instead of clicking.

Where Your Files Live

  • Files are stored inside folders, and folders can hold other folders
  • Directory is another word for folder. They mean the same thing, and you will see both
  • A folder inside another folder is a subfolder, or subdirectory
  • This nesting forms a tree, from your whole disk down to a single file
  • The folder you are working inside right now is the working directory

Opening the Terminal in VS Code

Two ways to do the same thing. Use whichever you remember.

  • From the menu bar: Terminal then New Terminal
  • Or by keyboard, Windows and Linux: Ctrl + `
  • Or by keyboard, macOS: control + `
  • A panel opens at the bottom. You type a command, press Enter, and it responds

Three Commands to Move Around

The names are abbreviations, and most of them are built on the word directory.

  • pwd is print working directory: the full path of the folder you are in now
  • ls is list: the files and directories inside the working directory
  • cd NAME is change directory: it moves you into the folder called NAME
  • cd .. moves you up one level, into the directory that contains you

If You Do Not Know Where You Are

  • Run pwd. It prints your exact location
  • Run ls. It prints what is in that location
  • Run cd .. to move up one level at a time
  • cd with nothing after it returns you to your home directory

Files Whose Names Begin With a Dot

  • A file or directory whose name starts with . is not shown by ls
  • ls -a lists all entries, including those
  • The -a is an option: extra instructions for the command
  • Nothing about the file is protected. The name only changes whether ls displays it
  • Course folders you download will contain some. You will need ls -a to see them

Making Folders From the Terminal

  • mkdir NAME is make directory: it creates a folder called NAME inside the working directory
  • It creates the folder only. It does not move you into it
  • Use cd NAME afterwards if you want to go inside
  • Run ls to confirm the folder is actually there

Set Up Now

Your Folder for This Course

One folder for the course, with a subfolder for activities and one for labs. Everything you download this semester goes into one of the two.

  • cmpsc100/
  •     activities/
  •     labs/

Building It, One Command at a Time

Type these one per line, pressing Enter after each.

  • pwd  check where you are before you create anything
  • cd Desktop  or wherever you keep your coursework
  • mkdir cmpsc100  create the course folder
  • cd cmpsc100  move into it
  • mkdir activities  then mkdir labs
  • ls  you should see both subfolders listed

Install Now

One More Tool: Git

We did not install this in the Week 1 setup, so we are doing it now.

  • Windows: download and run the installer from git-scm.com/download/win
  • macOS: run xcode-select --install and accept the prompt
  • Some Macs already have it. The command will say so, and that is fine
  • When it finishes, close and reopen the terminal, then run git --version
  • A version number means it worked. Full steps are in the Setup Guide, section 5

Next

What Git Is

  • Git is a program that records the changes you make to files in a folder
  • A folder that Git is recording is called a repository, usually shortened to repo
  • Each time you save your progress, Git stores that version and keeps the earlier ones
  • If you break something, the version that worked is still there to go back to
  • Git runs on your own computer and does not need the internet

Git and GitHub

  • Git is the program on your computer that records changes
  • GitHub is a website that stores repositories online, so they are backed up and shareable
  • You made a GitHub account during the Week 1 setup lab
  • Every activity and lab in this course is a repository on GitHub. You will be given a link to each one
  • This is how you receive your work, and how you hand it in

Clone: Getting a Repository Onto Your Computer

Cloning downloads a copy of a repository, and remembers which GitHub repository it came from.

  • git clone URL downloads the repository into your working directory
  • It arrives as a new folder, so cd into the right place before you run it
  • Activity repositories go in activities/, lab repositories go in labs/
  • Run ls afterwards to confirm the new folder is there

Commit and Push: Handing Work In

  • git add FILE marks a file to be included in your next save
  • git commit -m "what I changed" saves a snapshot of those files on your computer, with a short note
  • git push uploads your saved snapshots to GitHub
  • Commit as often as you like. Each one is a point you can return to
  • Your work reaches us only after you push. A commit on its own stays on your laptop
← Exit
1 / 14