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

Midterm Exam
Fall 2009
Friday 6 Nov 2009, 10:00-11:50
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 _______________/10 Problem 2 _______________/4 Problem 3 _______________/5 Problem 4 _______________/9 Problem 5 _______________/4 Problem 6 _______________/4 Problem 7 _______________/4 Problem 8 _______________/8 Problem 9 _______________/6 Problem 10 ______________/3 Problem 11 ______________/6 Problem 12 ______________/8 Problem 13 ______________/10 Problem 14 ______________/4 Problem 15 ______________/3 Problem 16 ______________/12
Total: ______________/ 100
1. Unix Utilities and File System [10 marks]
Write a one-line command for the following tasks:
a) Remove the empty directory tmp.
rmdir tmp OR rm CR tmp OR rm Cr tmp
b) Allow the user to execute the directory cgi-bin, but disallow everyone to write to it. Note that we do not know the original permission of cgi-bin.
chmod u+x ,a-w cgi-bin (numerical not accepted) OR chmod u+x cgi-bin; chmod a-w cgi-bin
c) Display the contents in the file dictionary.txt in lexical order.
sort dictionary.txt
d) Display the last 30 lines in the file longtext.txt.
tail -30 longtext.txt OR tail Cn30 longtext.txt
e) Append the date into the end of the file date.txt.
date >> date.txt
f) List the files and directories in long format for the directory inside your home directory. (You do not know your username however.)
ls Cl ~ OR ls Cl $HOME
g) Display the contents of the file textfile.txt with duplicate adjacent lines removed, and with line numbers.
uniq textfile.txt | cat -n
(1 mark for each side of pipe)
h) Display only lines which contain your own username to the screen showing who is logged on, where and when.
w | grep `whoami` who | grep `whoami` finger | grep `whoami` w | grep $USER
(1 mark for each side of pipe)
2. Links [4 marks]
a) What is the result shown on the screen after the following sequence of commands is executed? echo "testing" > testing.txt ; ln testing.txt\TESTING; ln TESTING testing; rm TESTING ; rm Cf\testing.txt ; cat testing
The text testing is shown on screen (1 mark)
b) What is the result shown on the screen after the following sequence of commands is executed? echo "testing" > testing.txt ; ln Cs testing.txt\TESTING; ln TESTING testing; rm TESTING ; rm Cf\testing.txt ; cat testing
testing is not found or error (1 mark)
c) What is the result shown on the screen after the following sequence of commands is executed? echo "testing" > testing.txt ; ln testing.txt\TESTING; ln Cs TESTI