CS32, Fall 2017

Lab01:
Orientation, and Linux basics


Goals for this lab

By the time you have completed this lab, you should be able to

Preliminaries (first lab only)

Step i. Create/verify your College of Engineering Account

By now you should already have a "College of Engineering" (CoE) computer account.

Only if you do not have a CoE account yet:

Log onto your account. If your username/password don't work - see troubleshooting login.

Step ii. Pair up

Choose a lab partner - you will work together with this person for the rest of this lab at least, and maybe for the rest of the quarter. An odd number of students in attendance will mean that one person will work alone today - the TAs will make sure it is only one person. Ask a TA for help if you cannot easily find a partner.

We hope this is not your first experience with "Pair Programming." If it is, then please try to pair with a student who is experienced. You will learn more about it as the quarter progresses. In short, there are two roles: pilot and navigator. The pilot types, and the navigator helps by observing, inspecting, thinking and suggesting - but neither of you directs the other. You are helping each other so that you both understand the work.

The TA has a sign-up sheet that you must fill out before proceeding to Step 0. Please record the following information on it:

Step by Step Instructions

Step 0: Choose initial pair programming roles, and log on

Choose who will be the pilot for the first part of the lab. The pilot should sit down in front of the computer now. The navigator gets a chair and sits next to the pilot. Please switch places (exchange roles) frequently - at least every 20 minutes or so - to ward off fatigue/boredom.

Log onto the pilot's account. If the pilot's account is not working, allow the navigator to log in instead. Whichever account you log into, you should remain logged into that person's account for this entire lab. Open a terminal window. As a reminder, that's the Application Menu, then System Tools, then Terminal Window.

Step 1: Create a directory for this lab in the pilot's account

This lab's pilot should log in. You will (both) work in this account for the rest of the lab.

Create a ~/cs32/lab01 directory and make it your current directory:

mkdir ~/cs32
mkdir ~/cs32/lab01
cd ~/cs32/lab01

Partner's note: sometime after lab you should create a ~/cs32/lab01 directory in your own account too. At least you will need a ~/cs32 directory for future labs. Generally, partners should share copies of your in-lab efforts after the labs end.

Step 2: Learn how to learn about some basic Linux commands

The man program can be used to find out details about commands, programs, standard library functions, and anything else for which a man page has been created. You just used mkdir and cd without any options, so why not learn more about those commands right now. First type:

man mkdir
With man, the space key moves to the next page, and Q quits. Notice that mkdir is a utility (program) to create directories, and it has three options available: -m to set the new directory's permission bits (mode), -p to create any necessary intermediate directories, and -v to be "verbose" about it. Try making a directory tree without specifying the -p option, for example:
bash-4.3$ mkdir one/two/three
mkdir: cannot create directory `one/two/three': No such file or directory
Oops. Let's try it again with -p, and also use the -v option to hear the details:
bash-4.3$ mkdir -p -v one/two/three
mkdir: created directory `one'
mkdir: created directory `one/two'
mkdir: created directory `one/two/three'
Aaah ... much better, and so informative!

Now learn some more about cd as follows:

man cd
Uh oh ... it seems that cd is a built-in shell command, not a program, and it does not have its own man page. If you spacebar down a ways though, you will find a section that starts out as follows:
cd [-L|-P] [dir]
       Change  the  current directory to dir. ...
That's all you really need to know in this case, which is a good thing since the rest of the text for this command is not very helpful (-L and -P both relate to symbolic links). Some built-in commands do have their own pages though, and so man is usually a good place to start looking for information. By the way, before going to Step 3, learn more about man as follows:
man man

Step 3: Learn about, then do (and record) something a bit more complicated

Here your task is to remove an entire directory tree with a single command. If you did not already create the one/two/three directory structure, then follow the Step 2 instructions to do so now.

Either rm or rmdir can be used to delete this whole directory tree with a single command. Learn how to do it first with one of these commands, then create the tree again and learn how to do it with the other command. Practice a bit both ways (recreating the directory tree whenever necessary). First use man to learn the appropriate options of course.

Only after you are done using the man program, begin a "script" of your session named lab01.txt by typing the following command:

script lab01.txt
All console text now will be copied to lab01.txt until you terminate the script by entering ctrl-D.
  1. Use rm (including the -v option) to remove the one/two/three tree with a single command.
  2. Recreate the directory tree one last time.
  3. Use rmdir (including the -v option) to remove the one/two/three tree with a single command.
Enter ctrl-D to terminate the script. View the script's contents (`more lab01.txt`) to be sure your work was accurately recorded. Go back and redo any tasks if necessary, before proceeding to Step 4.

Hey, by the way: did you ever try `whatis X` to learn about a command named X, or the apropos command that searches for strings in the whatis database? Both are worth trying. And one more thing to note: documentation for some commands is only available by executing the commands themselves, often with the --help option (yes, that's two hyphens).

Step 4: Use turnin to turn in your work

Turn in lab01.txt using the CS department's turnin program as follows:

turnin lab01@cs32 lab01.txt
Read the program's message(s) and respond as necessary until the following message indicates success:
*** TURNIN OF lab01 TO cs32 COMPLETE! ***
Mostly we just want to make sure that all students know how to use this turn-in program, so please remember these easy steps for whenever we ask you to turn in files for CS 32 in future weeks. Thanks.

Leave the terminal window open to show the TA its contents.

Step 5: Show off your work and get credit for the in-lab requirements

Get your TA's attention to inspect your work, and to record completion of your in-lab work.

Don't leave early though ... see "After lab-work is done" below. And don't forget to log out before leaving the lab.

Step 5a. ONLY IF YOU RAN OUT OF TIME TO HAVE THE TA INSPECT YOUR WORK

If you must complete this assignment at CSIL, then both partners must submit it separately using the turnin program.

Bring up a terminal window on CSIL to complete whatever work you still need to do. Then turn it in first from the account in which you are working by following the instructions above. Log out of the first account, and then log into the other partner's account. At this stage, you can either recreate the script in this other account (by redoing all the work), or you can use cp to copy the lab01.txt file to this other account. Either way, turn it in again from the other account too.


Evaluation and Grading

Each pair of students must accomplish the following to earn full credit for this lab work:

Full credit is 50 points.


After lab-work is done

The following tasks are meant for all students, not just those who finish the required lab work quickly. Other students are expected to work on these tasks outside of lab, over the course of the next week.

You should learn the purpose (at least) of each of the following Linux commands:

alias, awk, bash, cat, cd, chsh, cp, date, diff, echo, file, find, finger, grep, gzip, head, hostname, less, locate, lpr, ls, man, mkdir, mv, ps, pwd, rm, rmdir, sed, sort, tail, tar, touch, uniq, vi, w, wc, which, who, whoami

Expect exam question(s) about some of them.

Learn about the following items too:

  1. How to redirect stdin, stdout and stderr (with the redirecting of stdout/stderr to the same/different files).
  2. Environment variables, including the meanings of export and set
  3. Any Linux editor (emacs, vi, ... your choice). You must be able to use one for the next lab. We suggest emacs - here is an emacs help page to get you started.

Prepared by Michael Costanzo.