=========================preview======================
(comp111)[2010](f)midterm~2186^_10034.pdf
Back to COMP111 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
COMP111: Unix and Script Programming

Midterm Exam
Fall 2010
Thursday 4 Nov 2010, 15:30-17:20
Student Name: key
Student ID:
Lab Section:
Instructions:
This is a closed-book, closed-notes examination.
Write your name, student ID, and lab section on this page.
Answer all questions in the space provided.

For Grading Purposes Only:
Problem 1 /9 Problem 2 /8 Problem 3 /5 Problem 4 /10 Problem 5 /8 Problem 6 /6 Problem 7 /6 Problem 8 /4 Problem 9 /4 Problem 10 /8 Problem 11 /10 Problem 12 /10 Problem 13 /4 Problem 14 /8
Total /100



1. Unix Utilities [9 marks]
a) Write down T for true statements and F for false ones. (4 marks; 0.5 marks each)
1. The mv command renames a file.
T
2. The following command is invalid:
sort <names> names.sort
F
3. To check the current username, we can use whoami. To check the current directory, we can use whereami.
F
4. The following command is invalid:
ls > ls | ls
T
5. To check the usage of the command man, we use the following command:
mpage man

F
6. To display the contents of the file text with line numbers on each line, we can use the following command:
cat -n file
T
7. To display the current date and time, we can use the following command:
echo date
F
8. To display a sorted version of the file text and remove duplicated lines, we can use the following command:
sort text | uniq text
F
b) Write down the missing commands in the following scenarios. No temporary file is allowed, and only one single command is used (>, >>, < and |are allowed, but not ;). Assume the file text does not exist initially. The series of commands are closely related. (5 marks)
1. Scenario 1
$ cat numbers 29 8 84 19 7 10 26 24 $ (command A) 10 19 24 26 29 7 8 84 $ (command B) 7 8 10 19 24 26 29 84
A. sort numbers (0.5 marks)
B. sort Cn numbers (0.5 marks)
2. Scenario B
$ cat courses
COMP151
ELEC290
IELM311
MATH021
COMP104
ELEC152
ELEC151
COMP171
COMP252
ELEC102
ELEC254

$ (command A)
COMP151
COMP104
COMP171
COMP252
$ (command B)
$ cat text
COMP151
COMP104
COMP171
COMP252
$ (command C)
$ cat text
COMP151
COMP104
COMP171
COMP252
ELEC290
ELEC152
ELEC151
ELEC102
ELEC254
$

A. grep COMP courses (1 mark)
(or: cat courses | grep COMP)
B. grep COMP courses > text (1 mark)
(or: cat courses | grep COMP > text)
C. grep ELEC courses >> text (2 marks)
(or: cat courses | grep ELEC >> text)


2. Unix File Systems and Links [8 marks]
a) Write down a single command to change the file permission of a file useraccording to the following rules. (4 marks) (1 mark for correct use of chmod in all 3 questions, +1 mark for each q)
1. Remove all permissions of group, with all other permissions unchanged.
chmod g-rwx user
2. Everyone can read, only group and owner can write, no one can execute.
chmod 664 user OR chmod a=r,ug+w