CPSC 120 Principles of Computer Science Fall 2024

Lab 1
Introduction to Linux and Processing

Due: Fri 9/6 at the start of lab

Labs are due at the start of lab. It is OK if you show up to lab and copy your files to the handin directory at the very beginning of lab, but this should take at most a couple of minutes and you should not spend the next lab period finishing up the previous week's lab. I will check timestamps, and files handed in more than five minutes after the start of lab will be considered late.

See the policy on late work and extensions.


Introduction

This lab introduces the systems and software that you'll need to use in this course. Successfully completing this lab means that you are able to:

This handout contains a lot of information. Don't worry about memorizing all of the details the first (or even second or third) time through! Instead, pay attention to understanding the concepts and note what topics there is information about so that you can refer back to the handout for the details when you need them. (Eventually you will need to be able to carry out the tasks without reference to the handout, but it is fine to let that memorization come with use.)

Much of what is in this lab is informational, but there are some things you should actually do:

Some steps might just say "follow along". In that case there isn't anything specific that you need to do, but you should check out what is being talked about in that section e.g. when reading about the Ubuntu desktop, locate the elements mentioned.

This handout is meant to be read in order from beginning to end, so you should do the various tasks in that order. Keep in mind that is a good idea to look through each section or subsection in its entirety before beginning to carry out any actions contained in that section.


Linux

Computer science courses at HWS make use of an operating system called Linux. An operating system is the basic software that runs the computer — it controls the hardware of the computer (such as disks and memory) and runs application software (like word processing programs and web browsers). It is the first thing loaded when the computer starts up. You are most likely already familiar with the Microsoft Windows operating system and/or the Macintosh operating system. Linux is a version of Unix, an operating system often used for servers and in academic environments. One reason for Linux's popularity is that it is free and open source, meaning that not only can you download and run it for free, the underlying code is available to anyone to add to and modify.

There are actually many different versions of Linux, known as distributions. HWS uses a version called Ubuntu. Different distributions of Linux all work the same way underneath, but they may look different or be configured differently.

Accessing Linux

Linux computers are available in Rosenberg 009 and in the Math/CS department lab in Lansing 310.

You can also access a Linux virtual desktop remotely from your own computer. There are two options:

Logging In and Logging Out

Once you get to a Linux login screen, whether you are in the lab or using a virtual desktop, enter your HWS username and password to log in.

When you are done working or will be away from the computer for a while, it is important to log out (even on a virtual desktop). One reason is security — if you don't log out, anyone who comes along will have access to your account and all your files. Another important reason is etiquette — neither the number of physical computers in the lab nor the number of virtual desktops are unlimited, so tying up a computer you aren't using may block someone else out entirely.

If you will only be away from the computer for a short time, such as for a quick trip to the bathroom, you can lock the screen instead of logging out, but the same etiquette guidelines apply — a locked screen prevents others from using the computer, and a computer locked for a long period of time may get rebooted which risks you losing work if your files aren't saved.

How to log out or lock the screen is covered in the next section ("Navigating the Desktop").

Navigating the Desktop

Unlike Windows and MacOS, where the desktop that you interact with is bundled with the rest of the operating system, the desktop in a Linux system is just another component and you'll likely encounter different-looking desktops if you use different Linux distributions.

For a brief introduction to the Ubuntu desktop, see A Beginner's Guide to Ubuntu Linux.

Working With Files and Directories

As with Mac and Windows, files in Linux are organized into a hierarchical collection of directories. ("Directory" is the traditional Linux term while "folder" is more associated with Mac and Windows; there are technical distinctions between the terms but from a user perspective both terms refer to the same concept and can be used interchangeably.) Each directory can contain files and/or subdirectories, which in turn contain files and/or subdirectories, and so forth.

Use the Files application to manage your files and directories — copy, paste, rename, delete, and (for directories) create.

Naming Files and Directories

Unlike Windows, Linux is case-sensitive so cs120 and CS120 are two different things. Be careful to name things exactly as directed (including case).

When choosing names for files and directories, stick to alphanumeric characters (letters and numbers) and the symbols - (dash) and _ (underscore). Some other characters, such as spaces, are legal to include but require special handling in some contexts, causing problems when I am printing your programs for grading. Please don't use spaces in file and directory names!

Home, Root, and Pathnames

You have a home directory which contains your personal files. (This is similar to "My Documents" in Windows.) To go to your home directory, click the Home shortcut in the Files application.

Another directory is the root directory. This directory is the top of the file system — all other files and folders are contained, either directly or indirectly, within the root directory. In other words, you can start at the root directory and repeatedly open subfolders to reach any other file or folder on the system. To go to the root directory, click on "Other Locations" in the Files application and then click on "Computer" (which should be the first thing under "On This Computer").

Root and home directories are well-known, and you can simply say "the root directory" or "my home directory" and people will know what you are talking about. (There's also the Home shortcut in Files which lets you jump straight to your home directory.)

For files and other directories, however, it is necessary to give a pathname which specifies where the thing is located within the system's directory structure. Pathnames can be absolute, which means that the path starts from the root directory, or relative, which starts from some other directory.

The notation for writing down pathnames differs from one operating to another. In Linux:

For example, the absolute path /home/alice/work/todo.txt refers to a file todo.txt which can be found by starting at the root (/), opening the subdirectory home, opening the subdirectory alice within home, and opening the subdirectory work within alice.

Your home directory is /home/username, where username is your actual username, not the word "username". (For example, the user alice's home directory is /home/alice.) This is the directory you are taken to when you click on the Home shortcut in the Files application; the pathname tells you that you can also get there by starting at the root directory (/), opening the home subdirectory, and then opening the directory with your username within home.

~ provides a shortcut for referring to home directories. This is convenient because every user has their own home directory. For example, ~/work/todo.txt refers to a file todo.txt which can be found by starting in your home directory and opening the subdirectory work within your home directory. ~alice/work/todo.txt refers to a file todo.txt which can be found by starting the user alice's home directory and opening the subdirectory work within alice's home directory. Careful attention to detail is required here — ~alice refers to alice's home directory (/home/alice) while ~/alice refers to a subdirectory called alice within your home directory (/home/username/alice).

Sketchbook and Handin Directories

Processing stores your sketches in a directory it calls your sketchbook. To keep things organized, put the sketchbook inside another directory holding all of your files for this course. In particular:

Work for this course will be handed in electronically — no need to print anything! Handing in consists of copying your files to a special handin directory that has been set up so that I can access your work for grading. Your personal handin directory is /classes/cs120/handin/username where username is replaced by your username. (For example, user alice's handin folder is /classes/cs120/handin/alice.)


Processing

Processing programs (or sketches as they are called) are created and run within the Processing development environment.

Starting Processing

Start Processing using the Applications menu — look for its blue icon on the second page of the menu, or start to type "processing" in the search box.

The first time you start up Processing, you may get a welcome screen with some tips about getting started. Uncheck the "Show this message on startup" box so that you don't continue to get the screen every time you start Processing, then click "Get Started".

Sketchbook Configuration

By default, Processing uses a sketchbook directory in your home directory to store your Processing sketches. Changing that setting will make it more convenient to get your sketches saved in the right spot and to access them again later. (This is a one-time configuration — you don't need to do it again unless you want to use a different sketchbook directory or run a different installation of Processing, such as on your own computer.)

With Processing running:

Then delete the default sketchbook directory that Processing created to avoid future confusion:

Creating and Running Sketches

Processing opens a new sketch window by default when it starts. To create additional new sketches, open a new editor window with File->New instead of creating a new tab in an existing editor window — multiple tabs are for sketches that consist of multiple files, not for separate sketches.

Type your sketch in the editor window.

Save sketches with File->Save (ctrl-S). Make sure you save your sketch frequently (such as each time you run it) so that you don't lose work if Processing or your computer crashes unexpectedly. The first time you save a new sketch, you will be prompted for a name. Check that the path/folder name near the top of the save dialog shows ~username/cs120/sketchbook (there will be a little house icon next to your username instead of a ~), then enter the name in the box labelled "Name:" at the very top of the save dialog.

Run your sketch by clicking on the Play button or using File->Run.

Try this out:

With Processing running:

Opening Sketches

Open sketches from within Processing rather than clicking or right-clicking on the file from the Files application.

The File->Sketchbook... menu provides easy access to any sketches saved in the sketchbook folder. (Which should be all of them.) If you need to open a sketch saved somewhere else, you can use File->Open... instead.


Finishing Up

  1. Hand in the Zoog sketch — using the Files application, locate the lab1 directory inside your sketchbook directory and copy it to your handin directory. Check that it got handed in correctly — using the Files application, navigate to your handin directory, and verify that there is a directory called lab1 inside your handin directory and a file called lab1.pde inside the lab1 directory.

  2. For each of the following, give an absolute path name (starting with / or ~) for the file or directory mentioned. Email your answers to me (bridgeman@hws.edu), putting your answers directly into the body of the email (don't create a separate file and attach it).

    1. Your cs120 folder.
    2. Your sketchbook folder, where your Processing sketches will be saved.
    3. The lab1.pde file inside the lab1 folder in your sketchbook.
    4. Your own personal handin directory.
    5. The handed-in lab1.pde file inside the lab1 folder in your handin directory.
  3. If you haven't completed the introductory survey (on Canvas), please do so ASAP.

  4. (optional) If you have a laptop that you can bring to class and/or a computer that you'd like to be able to use instead of coming to the lab, test that you can connect to the Linux VDI — installing the desktop client is recommended but via a web browser is also an option.

If Lab is Over and You Aren't Done

You will not generally be able to finish the lab during the lab period. You can use the computers in Rosenberg 009 (when not in use for a class) and Lansing 310, connect to a Linux virtual desktop remotely, or use your own computer if you have Processing installed (see below).

If You Have Extra Time

There's not any graded extra credit for this lab, but if you have additional time:


Processing On Your Own Computer (Optional)

Accessing Processing through the Linux VDI (or in the lab) is recommended, but it is also possible to install Processing on your computer for better performance or so you can work without a constantly-active network connection.

You will need to download and install two things — Processing (for writing your programs) and FileZilla (to transfer your files between the Linux filesystem and your own computer):

Once you've installed Processing, start it up and configure the sketchbook directory as you did above. You should then be good to go.

You will need FileZilla to copy any files from Linux to your computer and vice versa. Once you start FileZilla, do the following to Math/CS department server:

Note: you must be on campus and connected to HWS Private (or using wired Ethernet) in order for this to work. If you are off campus, there's an extra step of setting up and running VPN. See Configuring Off-Campus Access to the HWS Network [Windows], Configuring Off-Campus Access to the HWS Network [MacOS], and Connecting to HWS Network from Off-Campus (VPN) for more information.

If the connection is successful, you'll see two directory listings. On the left side, labeled "Local site", you'll see your computer. On the right side, labeled "Remote site", you'll see the Linux filesystem.

To copy files, navigate to what you want to copy on one side and where you want to copy it on the other, then drag the file(s)/directories(s) from one side to the other. For example, to hand in a sketch, navigate to your sketchbook directory on your local computer and to the handin directory on the remote Linux filesystem, then drag the entire directory containing that sketch from the left side to the right side.

You can backup your work too — copy the sketch directories from the sketchbook on your computer to ~/cs120/sketchbook on the Linux system.