=========================preview======================
(COMP111)midterm-Fall2007.pdf
Back to COMP111 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
COMP111: Unix and Script Programming
Midterm Exam
Fall 2007
Wednesday 14 Nov 2007, 08:20-09: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 _______________/4
Problem 2 _______________/8
Problem 3 _______________/3
Problem 4 _______________/6
Problem 5 _______________/12
Problem 6 _______________/5
Problem 7 _______________/6
Problem 8 _______________/7
Problem 9 _______________/5
Problem 10 ______________/3
Problem 11 ______________/3
Problem 12 ______________/4
Problem 13 ______________/6
Problem 14 ______________/13
Problem 15 ______________/2
Problem 16 ______________/3
Problem 17 ______________/3
Problem 18 ______________/7
Total: ______________/ 100
1. Unix Utilities [4 marks]
Answer TRUE or FALSE (0.5 marks each):
a. The following command can show the contents of the file textfile: cat `textfile` F
b. The following command can show the file textfile page-by-page on the screen: more | textfile F
c. The command lpr is for printing a file. T
d. The following command lists the directory contents into two files: ls > file1 > file2 F
e. The following command renames the file textfile as nottextfile: ren textfile nottextfile F
f. The following command cannot print the last 5 lines of textfile: tail +5 textfile T
g. The following command prints all the lines containing midterm in the file textfile: grep textfile midterm F
h. The command pwd is for changing the user password. F
2. Unix File System [8 marks]
Assume the following commands have been executed:
$ whoami
chuckjee
$ ls -l
total 8
--w--w--w- 1 chuckjee cs 28 Nov 5 14:13 date
drw-r--r-- 2 chuckjee cs 17 Nov 5 14:12 folder
lrwxrwxrwx 1 chuckjee cs 4 Nov 5 14:29 text -> date
-rwx--x--x 1 chuckjee cs 7 Nov 5 14:14 whoami
$ cp date folder
a. What will happen after these commands are executed? Why does an error occur? (2 marks)
Error: permission denied / unable to stat (1 mark) EITHER - I have no execution permission for chuckjee on the directory folder. (1 mark) OR C I have no read permission for chuckjee on the file date. (1 mark)
b. What command should be executed to eliminate the error in part (a) above? (2 marks)
1. chmod 744 folder / chmod u+x folder / anything adding execute permission to user (1 mark)
2. chmod 622 date / chmod u+r date / anything adding read permission to user (1 mark)
c. Can others see the contents of the file date?