CPSC 120: Introduction to the Math/CS Linux System

(Adapted—only slightly—from a tutorial by Prof. Stina Bridgeman)

Home | Calendar | Announcements | Assignments | Example Code | Notes

Introduction

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.

Most of you are familiar with one or more of the Microsoft Windows operating systems such as Windows XP, Vista, Windows 7, and Windows 8. Some of you may also have used a Macintosh, which uses the MacOS operating system - Snow Leopard, Lion, and Mountain Lion are recent versions. Some of you might even have used Linux, the operating system that the Math/CS Department uses on its computers. Linux is a version of Unix, an operating system often used for servers and in academic environments.

This tutorial will introduce you to the Linux environment at HWS. You'll learn how to start Linux, navigate the desktop, navigate the file system and copy files, use a text editor, and print things. Later labs will introduce the Processing development environment that you'll use for most of the course.

(There are actually many different versions of Linux, known as distributions. HWS uses a version called Linux Mint. All versions of Linux work the same way underneath, but different distributions may look different or be configured differently.)

Don't worry about memorizing all of the details in this handout. Just make a note of what information there is, so that you can come back and look up how to do something when you need to.


Starting Linux

Rosenberg 009 has computers configured to run both Windows and Linux. Only one operating system can control the computer at a time, so these computers are configured as dual-boot machines. When you sit down at one of these computers, it will probably be running Windows.

To switch to Linux:

As the computer restarts, you will eventually see a screen with a menu that allows you to choose "Windows" or "Linux Mint".

Wait some more, and eventually you will get the Linux login screen.

If you are working on assignments outside of lab, you can work in Rosenberg 009 (when not in use for classes) or in the Math/CS Department computer lab in Lansing 310. The Math/CS Department lab has 12 dual-boot computers (Linux and Mac OS X) primarily running Linux, so you will generally not need to reboot them.

You can also use your own computer to connect to a Linux machine from your room. If you have a Windows computer, you'll need to install a free program called VNC which will allow you to connect to a computer in the Lansing lab. See the "VNC" section of Professor Eck's Using Linux at HWS document for information on how to obtain and use the software. If you have a Macintosh, you can use VNC or ssh (see the "SSH" section of Using Linux at HWS). See me if you need help getting things set up.

Regardless of how you start Linux - by sitting down in front of a computer in Lansing 310, by rebooting a computer in Rosenberg 009, or by using VNC or ssh to connect - you should now have a login screen or prompt where you can enter your username and password.


Logging In

You will be provided with a username and password in lab. Note that while your username might be the same as your email login, this is a separate account from your HWS network account and has a separate password.

Wait while the desktop starts up. (This may take a while, especially the first time you log in.) If this is your first time logging in, some windows may pop up displaying information or allowing you to configure your desktop. Close or otherwise dismiss those windows - ask if you get one that you aren't sure about.

You should end up with something like this:

desktop


Running a Web Browser and Finding the Lab

To save paper, the remainder of this lab and all other labs for the course will be only posted online. To view it, you'll need to start a web browser:

Bring up the Applications menu:

selecting firefox from the applications menu

On the Applications menu:


Once Firefox starts up:


Logging Out or Rebooting

When you are done working for the day or are going to be away from the computer for a while, you need to be sure to log out - if you don't, anyone who comes along will have access to your account and all your files!

applications menu

To log out:


If you are in Rosenberg, you will also need to reboot the computer back to Windows for other lab users.

To reboot:


The Cinnamon Desktop

Unlike Windows and MacOS, where the desktop that you interact with is bundled with the rest of the operating system, Linux supports many different desktops with different features and appearances. The desktop used at HWS is called Cinnamon.

- google chrome is also available - If you know the name of the application you are looking for but not how it might be categorized, you can look under "All Applications" or type the name of the application in the search box at the top of the menu window.

The Cinnamon Desktop is most similar to the desktop in Microsoft Windows, and you'll notice a number of common features. One such feature is the bar running across the bottom of the screen - Windows calls it the taskbar; Cinnamon calls it the panel.

panel

You've already encountered the Menu icon (on the left side of the panel) and the Applications menu (similar to the Start menu in Windows). You can locate applications by navigating through the appropriate category (like you did to start Firefox), going to "All Applications" and looking for what you want, or by typing the name of the application in the search box at the top of the Applications menu.

There are a number of other icons in the panel. On the left side (near the Applications menu), you may have icons for launching common programs such as Firefox. On the right side, you may find a clock and some icons for controlling settings such as sound volume. If you move your mouse over the icons and wait for a moment, a message will often pop up telling you something about it.

As you start up different programs, the large empty area in the middle of the panel will fill with tabs those running programs. (There should be a tab for Firefox, for example.) As in Windows, you can restore minimized windows or bring up a window that got buried by clicking on the appropriate tab.

On the desktop itself, you may see two icons labeled "Computer" and "home" in the upper left corner - these provide access to your files. (More on that later.)


The Commandline

As with Windows and Mac, much of your interaction with Linux can happen by clicking on icons and menus. However, some tasks require the use of the commandline where you type in the command you want to run. (Much of what you do with icons and menus can also be done via the commandline, but we'll only use it when necessary.) Both Windows and Mac also provide a commandline interface - perhaps you've used it.

The Linux commandline is accessed through a terminal window.

To start a terminal window:


Changing Your Password

You should change the random password you assigned to something only you know and which is easier for you to remember. You can use the same password as your HWS network account if you want, or something different.

You can use any characters except spaces in your password - you should avoid real words (including real words spelled backwards), and use a mix of letters and non-letters. Also, your password is case-sensitive, so make sure the "Caps Lock" key isn't on unless you mean for it to be.

To change your password:

If your password was successfully changed, you should see a message to that effect.


Navigating and Naming Directories

As in any operating system, files in Linux are organized into folders (often called directories in Linux). Each folder can contain files and/or subfolders, which in turn contain files and/or subfolders. At the top of this hierarchy is the root folder - all other files and folders are contained, either directly or indirectly, within the root folder. In other words, you can start at the root folder and repeatedly open subfolders to reach any other file or folder.

You can use a program called Nautilus to navigate through your directories and manage files and folders.

To start Nautilus:

Home Directory

You have a home folder (or in Linux terminology a home directory), which contains your personal files. (This is similar to "My Documents" in Windows.)

To go to your home directory:

You should see something like the following: (it may not be exactly the same)


Naming Directories

For some special folders, like the root folder and your home folder, you can simply say "the root folder" or "my home folder" and people know what you are talking about. However, for other files or folders, the only way to specify which thing you are talking about is to explain how to find it - and it is useful to have a concise way of writing down this explanation. The exact representation varies from operating system to operating system, but in Linux we concatenate the names of each folder from some starting point to the folder containing the item, putting a slash (/) between each folder name. This is known as the path to the item. For files, the name of the file is appended to the path.

The root folder has a very short path: / (just a slash).

The path for your home directory is /afs/afs.hws.edu/home/username, where username is your actual username, not the word "username". This means that your home directory is in a folder called "home" which is in a folder called "afs.hws.edu" which is in a folder called "afs" which is in the root directory (indicated by the / at the beginning of the path).

There's also a special shortcut that can be used to refer to your own home directory. It's very short: just ~ (a tilde).

A second shortcut can be used to refer to a particular user's home directory: ~bridgeman, for example, refers to the user bridgeman's home directory (i.e. mine). You could also refer to your own by putting your username instead of "bridgeman" (but leave the ~ in there exactly as shown). It would also be fine to use the full path /afs/afs.hws.edu/home/bridgeman instead of ~bridgeman to refer to my home directory.

Note: details matter! ~bridgeman means bridgeman's home directory while ~/bridgeman means the directory called "bridgeman" within your own home directory.

Changing Directories

To change directories in Nautilus, you can double-click on a folder icon as you would in Windows or Macintosh. You can back up to a previous folder by clicking on the back arrow in the upper right corner of the Nautilus window, or jump to a particular folder higher in the hierarchy by clicking on its name displayed just above the area showing your files and folders. (Click on the little left-pointing triangle to reveal the full path if needed.) You can also go straight to certain directories by clicking on one of the entries displayed on the left side of the Nautilus window. ("File System" takes you to the root directory.)

One directory that you'll need later on is the handin directory. This is a directory I've set up so that I can access your work for grading.

The handin directory for this course is /afs/afs.hws.edu/classes/cs120.

Inside the handin directory, you'll find a folder labelled with your last name. That's your own personal handin folder, and that's where you'll copy your files when you are ready to hand things in.


Working with Folders and Files

Creating Directories

To keep things organized, you should create a directory to hold the files you'll create for this course.

This will create a new folder called "Untitled Folder", with the folder name highlighted and ready for editing.

Note that unlike Windows, Linux is case-sensitive so cs120 and CS120 are two different directories. You should be careful to observe the case of things when typing in names.

Since you created the cs120 directory in your home directory, its path would be /afs/afs.hws.edu/home/username/cs120 (again, with your own username in there instead of "username"). Or you could use the first shortcut (~/cs120) or the second shortcut (~username/cs120 - with your own username, of course).

It's also a good idea to have a separate directory for each lab or project.

Selecting Files and Folders

You can select files and folders like you do in Windows - click on a file or folder to select just that item, or click on a file or folder and then shift-click on another file or folder to select the range of items between the two, or click on a file or folder and then ctrl-click on others to include them, or click in the background of the Nautilus window and drag to select all of the files/folders in a region.

Deleting Files and Folders

Sometimes you will need to delete a file or folder. You have two options: delete (making the item gone for good) or moving it to the trash (where you can delete it for good or restore it to its original location).

To delete file(s) and/or folder(s):

The trash can be accessed via the list on the left side of Nautilus window if you want to restore an item or empty the trash.

Give it a try:

Moving and Copying Files and Folders

To move files and folders from one place to another, you can open two Nautilus windows, navigate to the folder containing what you want to move in one and the target location in the other, and drag the file(s)/folder(s) from one window to the other.

You can also select, cut or copy, navigate to the target folder, and paste to move or copy files. Access cut/copy and paste through the Edit menu or by right-clicking on a selected item (cut/copy) or in the background of the Nautilus window (paste).

Give it a try:

Renaming Files and Folders

To rename a file or folder, right click on the item you want to rename and select "Rename..." or select the item and choose "Rename..." from the Edit menu. Then type in the new name of the file. Make sure you include the appropriate extension (e.g., ".html" with HTML files, ".txt" with text files, ".doc" word documents, etc.).


Text Editors

Most of the time you will be creating and editing files within the Processing environment. Sometimes, though, you'll need to create other kinds of files (such as text files). Linux provides several text editors suitable for working with text files, but I recommend using gedit.

To start gedit:

There are a few exercises at the end of the lab handout that ask you to write up your answers. While you don't have any answers yet, you can get started by creating a file with your name, the date, and the name of the lab.

For readability, please keep each line of the file to 80 characters or less. (This is the amount of text that fits on one line when the file is printed.) It's easy to forget to do this because gedit will automatically wrap long lines when you get to the edge of the window - but this is just a display thing, and doesn't insert line breaks into the file.

To edit an existing file, you can either use Nautilus to navigate to the folder that contains it, right-click on the file, and choose "Open With Text Editor" (at the very top of the menu) or you can start gedit and choose "Open" from the File menu.


Handing in Your Labs

You will be handing in your labs and projects electronically so you do not need to print your files for handin. Try this now to make sure you understand the process.

To hand in your files:


Printing

You will be handing in your labs and projects electronically so you do not need to print your files for handin. However, it is still sometimes useful to print something out.

Most GUI programs provide their own printing functions (usually under the "File" menu), though not all Linux programs are well-behaved about printing. If you choose to print out the lab handouts, please save paper by going to the "Page Setup" tab (after choosing "Print" in Firefox) and set "Pages per side" to 2. (A similar option is available in other programs besides Firefox - it's worth looking for.)

When you go to print, you will see a list of available printers. You should use only cslab (in Lansing 310), ros009 (in Rosenberg 009), or libmul (in the Library Multimedia Lab). Do not use faclw or mfd - these are for faculty use only. Note that Linux can only print to printers it has been configured for, so you can't print to your own printer in your dorm room.


John H. E. Lasseter