Introduction
Announcements

Schedule
Labs
Assignments
TA office hours

Tests, exam

Topic videos
Some course notes
Extra problems
Lecture recordings

Discussion board

Grades so far

CSC 209 midterm

22 October 2012, 13:10

Aids permitted: Any paper. Calculators are not permitted.

There are five questions and they are equally weighted.
Time allotted: 45 minutes.

Since time is short, be careful not to get stuck on one question to the exclusion of others. Not everyone will necessarily be able to finish this test within the 45 minutes. The amount of marks or answer-space allotted does not indicate how long it will take you to complete the question, nor does the size of the answer-space indicate the size of the correct answer.

Answer all questions. Answer questions in the space provided.

Do not open this booklet until you are instructed to.


1.

Describe in English what patterns of file names in the current directory the following "glob" expressions match. Ignore the issue of file names beginning with a dot. The answer for part 'a' is supplied as an example.

a) *x

Solution:

File names ending with an x


b) *x*y*

c) x*x*x

d) *.x

e) *.*

[Solutions]


2.

Write a 'while' loop in sh to output the numbers from 1 to 10, by starting with '1' and adding one to it each time around the loop to get the next number. (E.g. don't use seq.)

[Sample solution]


3.

A shell script containing the following code is executed:

	if x
	then
	    y
	else
	    z
	fi

a) Write the command 'x' (either as a shell script, or in C if you prefer) so that the command 'y' will be executed.

b) Write the command 'x' (either as a shell script, or in C if you prefer) so that the command 'z' will be executed.

[Sample solutions]


4.

"for i in *" can be used to loop over all file names in the current directory.

Use this to write shell commands which check whether each file in the current directory contains the string 'good' in the opinion of grep.

For each file containing 'good', output a line of the form

        file is good... file is *very* good.
where "file" is the file name.

[Sample solution]


5.

Here is a portion of a unix filesystem. Like the "ls -l" output, we list whether the file (inode) is a plain file, directory, etc, with '-' for plain file or 'd' for directory. In the case of directories, the table also states the data content of the directory itself (a list of pairs of name and inode number).

2d. 2, .. 2, usr 8, etc 4, bin 7
3- 
4d. 4, .. 2, passwd 3
5- 
6d. 6, .. 8, fsys.fig 5, src 21
7d. 7, .. 2, date 18
8d. 8, .. 2, bin 9, ajr 6, you 22
9d. 9, .. 8
10  
11  
12  

a) Suppose I do "mkdir /usr/ajr/newdir". Write in all changes/additions to the above list. (There are some free inodes at the end for you to use for new files.)

b) Suppose that my current directory is /usr/ajr and I do "ln fsys.fig more.fig". Write in all changes/additions to the above list.

[Solutions]