Lab overview
Lab 01
Lab 02
Lab 03
Lab 04
Lab 05
Lab 06
Lab 07
Lab 08
Lab 09
Lab 10
Lab 11
Lab 12
Lab 13
Review

[Course home page]

CSC 209 lab 01 exercises, week of 10 May 2022

[solutions are available (requires teach.cs authentication)]

Part 1: Logging in

Please attend tutorials based on the first letter of your surname: If you want to switch tutorials for some reason, please check this with the TA of the tutorial you are switching into, in case they have space concerns.

The first thing you need to be able to do is to "log in" to the CS Teaching Labs computers. If you didn't bring a laptop, you can use a workstation in the tutorial room. If you did bring a laptop, or to log in from home or elsewhere later, you will need to use the "ssh" protocol for remote login.

Note that your Teaching Labs account name is the same as your UTORid. But it's the same as if by coincidence — your account is not connected to your UTORid in any other way, and for example the password is independent (although you can set it to be the same if you want).

If you haven't set your password, or you don't remember it, you can use your UTORid credentials to set or reset your Teaching Labs password. If you're sitting at a workstation, log in with user name account, password account. From anywhere else, just go to https://www.teach.cs.toronto.edu/account
The password change is instantaneous. (But do look at the output to see if it objected to your password for not being strong enough.)

Then, you can log in. Most OSes these days have a command-line ssh program, now even including MS-Windows. The command you will use will look like this, if your account name is smithw6079:

	ssh smithw6079@teach.cs.toronto.edu
There's more information on the CSC 209 web page remotelogin.html .

If you have problems logging in to your account, try consulting items #1 and maybe 2 in https://www.teach.cs.toronto.edu/vfaq.html
Or ask me or a TA for help.


Part 2: Getting to the command-line

Linux these days has all sorts of user-friendly things you can click on, but that's not what we're going to be looking at in this course. As we are discussing in this course, you can always do more from the command-line.

If you have logged in via ssh, you are already at the command line.
If you are logged in on a workstation, you can get to a command line by running an application program called "Terminal", whose icon resembles an old-fashioned CRT monitor, with a '>' prompt on it and an underline cursor.

Today's lab is about becoming familiar with the command-line environment. If this lab is trivial for you, great! Submit it and get your 1%. But I need to be sure that everyone can do this basic use of the command-line so that we can proceed with the course.

This lab also involves an even-more-trivial familiarity with the bulletin board system we will be using for asynchronous group discussion in this course.


Part 3: Attendance requirement (necessary for credit)

To get the grades for the in-person component of the lab, you must attend the tutorial. If there is some legitimate reason that you are unable to attend the tutorial, please e-mail me to request an exception, as you would with any term work requirement.

Taking attendance is self-managed as much as possible. If you are logged in at a workstation, you can register your attendance by typing this command in a terminal window:

	/u/csc209h/summer/present

If you are not logged in at a workstation, there's no way for me to tell whether or not you are in the tutorial. In this case, please tell your account name (UTORid) to the TA and they will mark you as present. Then, please check that you are correctly marked as present by checking the web page
https://wwwcgi.teach.cs.toronto.edu/~ajr/cgi-bin/auth/present


Part 4: Some command-line exercises

Work on these exercises for a while, and then the TA will take them up.


1. In /u/csc209h/summer/pub/lab/01 you will find a file named "chapter1" and a file named "chapter-one". One of these files is a text scan of the beginning of a Sherlock Holmes novel, with an error in it (because "optical character recognition" is not perfect). The other is that file corrected. But the person who did this named them poorly, and then e-mailed them to you so you lost the timestamp on the file so you don't know which is which.

Which is which?


2. This command will output all file names in the current directory which contain an 'x' in them (anywhere in the name):

        echo *x*

This command will output all file names in the current directory which contain an 'x' at the beginning of the name:

        echo x*

Write commands to output the following. Some of them may require a different approach. Keep your answer as simple as possible. (Do not worry about the issue of files whose names begin with a dot.)
a) file names containing an 'x' at the beginning and another 'x' somewhere else in the name
b) file names containing an 'x' at the beginning and maybe another 'x' somewhere (or maybe not — that is, include both categories of such files)
c) file names containing an 'x' anywhere in the name
d) file names containing two 'x's in the name (anywhere)
e) file names containing both an 'x' and 'y' in the name, anywhere, in either order


3. In /u/csc209h/summer/pub/lab/01 there are a number of identical files named [0−9], except that one of them is not identical. Which file is the odd one out?


4. How many times does the word "the" appear in the file chapter1?

What is the second-commonest word?


5 (as time permits). Experiment with that demonstration command for producing a word frequency list. Put in one component at a time to understand what it does, i.e. first the "tr" command, then that command piped to the next tr command, and so on.
tr -cs a-zA-Z0-9 '\012' </u/ajr/public_html/209/textbooks.html | tr A-Z a-z | sort | uniq -c | sort -n


If you have further time before the TA begins to "take up" these questions, think of variant approaches for question 3, or ways to do it better, or ways that you might be able to do it if it were a thousand files instead of ten.


Part 5: Basic use of an editor... but in a terminal window (for credit)

The purpose of this part of the lab is to use an editor to create and edit some text files on a teach.cs computer. You really need to do this exercise even if you have substantial previous computer-using experience. In the latter case, it might be very quick and just serve as a check of your abilities... or you might find that there's something you need to clear up.

This exercise MUST be done on a teach.cs computer (either on a lab workstation, or remotely using ssh or x2go). And it must be done all inside a terminal window (such as in ssh). I know you know how to create files on your own computer, and I know you know how to click on a button which says "create a file". That's not what we're doing here.

1. Create a small text file named "sample" using an editor.

2. "cat" the file, to see that you created what you thought you did.
Does it "end in the middle of a line"? If so, your session will look like this:

	$ cat sample
	This is a file.$ 
with the next prompt at the end after the period there. (Your shell prompt is probably more verbose than a simple '$', but anyway, with the prompt at the end after the period there.)
Some editors don't let you do this; some do. But usually we don't like to do this. A text file generally consists of zero or more lines, where each line consists of zero or more non-newline characters followed by a newline character. That is to say, if the file is not empty, the last character should normally be a newline for us to consider it to be a normal text file.

3. Make the file perfect. You need to be able to use your tools precisely. No extra blank lines, but not ending in the middle of a line either. Check with 'cat'.

4. Make a copy of a computer program file you wrote for some other course, using the command-line, not an IDE (such as Wing-101 or Eclipse — DON'T use such things). (If you don't have one around, write a trivial program in the programming language of your choice... but again, without using an IDE, just a simple text editor.)

5. Modify this program slightly, without using an IDE.

6. Run the modified program, without using an IDE.

(Why not use an IDE? Well, once you get a car you might start driving everywhere, but if your destination is just across the street you're going to waste time trying to drive there instead of simply walking across the street. It is important that you are able to create and manipulate files without necessarily using an IDE. You need to be able to walk from the parking lot into the store, and you will find all sorts of other reasons to walk rather than to drive, from time to time. It's a more fundamental skill. You need both skills.)


Part 6: Submit (necessary for credit)

To get credit for part 5 above, you need to "submit" the files, which just copies them to an internal directory for grading purposes.

You submit with a command like this:

	submit -c csc209h -a lab01 sample gcd.py
In this command, the "lab01" is the "assignment" name you are submitting under, and the "sample" and "gcd.py" are the files to submit. Substitute "gcd.py" with your own file name, of course.

You can submit files one at a time, or you can submit any number at once. For now, submit your two files you've done so far, to make sure you know how to do this while you're in a class with a TA.


Part 7: Another problem

At this point you are probably nearing the end of the scheduled tutorial time. It's not anticipated that all of the lab problems can be done during the tutorial time.

Here is a problem (not for credit) to work on in the time remaining, and later as interest permits. There will be a video solution posted. There are further problems below which are also for credit which you almost certainly won't get to during the tutorial time so must do later in the week.

I have a puzzle game on my phone where there are 1001 different puzzles at the "hard" level. The screen on which you can select which puzzle to do next looks like this:

I keep pressing "random" and it gives me a random one of the puzzles which I haven't solved yet (but might have tried).

But that picture is from rather a while ago. I've now solved and tried many more of the puzzles. I've copied and pasted the current "solved" and "started" lists into the files /u/csc209h/summer/pub/lab/01/solved and /u/csc209h/summer/pub/lab/01/inprogress .
As you can see (how?), I've solved 957 of the 1001 puzzles.
And I've failed to solve 43 of the remaining 44.

I really want to try that one fresh one I've never tried yet, but I can't see which number it is!

Find out which puzzle number is the puzzle number from 1 to 1001 inclusive which is not listed in either list.

Note: This problem is tricky! The video will discuss its solution at some length. But see what you can do on your own first. Or in small groups.


Part 8: A little shell program (for credit)

In shell commands there is usually no need for a "print" statement, because you simply run commands which produce the desired output. For example, when you did "cat" on a file above, you didn't need to print the results, that's what the cat command already does.

But sometimes we want something like a print statement, most commonly in cases where in a normal programming language we would write "print" with static text (e.g. "print 'Your password has been changed.'"). Our particular choice of static text is not necessarily going to happen to be the output of any existing command.

So, there is a command for this purpose. It is called "echo", and it just prints (echoes) its arguments.

Try typing "echo hello" at the command prompt.

We can put a list of shell commands in a file and execute that list of commands. In fact, the shell input language is a complete programming language, as we will see over the next week or so.

For today, just produce a file named "story" which prints (echoes) three simple lines of text of your choosing.

Put the three "echo" commands in a file, so that you can execute the commands in that file by typing "sh story".

Experiment with this a bit.


Part 9: Bulletin board (for credit)

This part isn't really about course content, but I also want to take this time to be sure that everyone is familiar with the bulletin board system we will be using for group discussion. So, one component of your lab grade will be the successful posting of a message there.

The bulletin board is at https://bb-2022-05.teach.cs.toronto.edu/c/csc209

We also have a "test postings" bulletin board at https://bb-2022-05.teach.cs.toronto.edu/c/csc209test

If you have something you want to post on the bulletin board already, great! Please do so. Otherwise, if you are just posting to get this grading point, or you are posting a test message, please be sure to post in the "test postings" bulletin board. A test posting in the main bulletin board will not get the point.

When you are looking at your message in your web browser, you will be on a URL which looks like: https://bb-2022-05.teach.cs.toronto.edu/t/test-message/3

Copy and paste this URL into a text file named "post", which we will use to verify that you posted something.


Part 10: Submit everything else (necessary for credit)

Parts 5, 8, and 9 above involve creating files for credit. You must "submit" all four of these files to get the mark for this lab. (Future labs will have more substantial requirements.)
You also have to get your attendance checked during the tutorial (part 3 above).
You probably already submitted "sample" and your example program in part 6 above, so you don't have to re-do that.

You can check which files have been submitted with the command

	submit -c csc209h -a lab01 -l
(that's minus 'l' for "list", not a 'one')

To submit files, first of all I suggest checking that your files do contain what you think they contain by using the "cat" command.
Expected files for lab 01 are:

  1. a simple plain text file named "sample" (beginning of part 5 above)
  2. a computer program file of some kind (also as in part 5) (must be plain text just like the other files)
  3. your shell script named "story" with three echo commands (part 8 above)
  4. your file named "post" containing the URL of your bulletin board posting (part 9 above).

Normally the 'submit' system won't let you submit files under the wrong file name, but for lab 01 I couldn't configure it that way because I don't know what your computer program file will be called. So please check the file names, and e-mail me with any problems.

The deadline for each lab in this course is the end of Friday (midnight). In this case that would be the end of Friday May 13. Late submissions are not accepted without a good reason and a written explanation (but if you are late, DO submit it immediately, then e-mail me the explanation).

You can submit files at any time before the due time, and you can submit them in a group as above or individually. You can resubmit a file by using the −f option, e.g.

	submit -c csc209h -a lab01 -f story

If there are any problems with this, send e-mail. Problems running the 'submit' command will not generally be accepted as a reason for lateness.

As mentioned in part 3 above, there is a tutorial attendance requirement to get the marks for the lab. Please make sure that you have got your attendance registered during the tutorial time, either by typing the 'present' command on the console of a lab workstation, or with the TA.

Important academic offence note!

Your work in this course which is submitted for course credit must be your own. Representing someone else's creative work as your own is an academic offence.

The lab work in this course is individual. You can discuss the items which are not for course credit with anyone, but the items which are submitted for course credit must represent your own work. It is also an offence to assist others in committing an academic offence (e.g. by providing your solution to them).

If you have questions about work to be submitted for course credit, ask a TA or the instructor (perhaps by e-mail). More information at the end of the course information sheet.