0% found this document useful (0 votes)
28 views3 pages

COSC 224 Exam (1) GGH

The document is an examination paper for COSC 224: UNIX OS and Programming at Chuka University, intended for second-year Computer Science students. It includes various questions related to UNIX commands, shell scripting, file permissions, and programming tasks in both shell and Perl. Students are required to answer one compulsory question and any two additional questions within a two-hour time frame.

Uploaded by

kimutaiallan16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

COSC 224 Exam (1) GGH

The document is an examination paper for COSC 224: UNIX OS and Programming at Chuka University, intended for second-year Computer Science students. It includes various questions related to UNIX commands, shell scripting, file permissions, and programming tasks in both shell and Perl. Students are required to answer one compulsory question and any two additional questions within a two-hour time frame.

Uploaded by

kimutaiallan16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COSC 224

CHUKA UNIVERSITY

UNIVERSITY EXAMINATIONS

SECOND YEAR EXAMINATION FOR THE AWARD OF DEGREE


OF BACHELOR OF SCIENCE IN COMPUTER SCIENCE (Y2S2)
COSC 224: UNIX OS AND PROGRAMMING

STREAMS: BSC (COMP. SCI) Y2S2 TIME: 2 HOURS

DAY/DATE: TUESDAY 09/4/2019 8.30 A.M. – 10.30 A.M.


INSTRUCTIONS: Answer Question ONE and any other TWO questions.

Question One (Compulsory) (30 marks)

(a) Explain what the commands shown below will do when excuted.
(i) cat /etc/passwd | sort (3 marks)
(ii) sudo userdel –r xyz (3 marks)
(b) Write Unix commands for doing the following: (4 marks)

Capture at least five names of cities in Kenya from the


keyboard. This list should be combined with the list
present in a file “cities.txt”. From the combined list
sort the city names in ascending order and store the
sorted list in the file “sortedcities.txt”.

(c) Explain the three types of file permissions in UNIX. Give at least one example of file
permission display on how they arranged in UNIX. (4 marks)

(d) Write a shell script to rename all file names in the current working directory that end with
.txt to end with .c (4 marks)

(e) Write a perl script to search all usernames in the home directory that begin with letter c
sort them and write them in a file “cusernames.txt”. (4 marks)

(f) Explain the two modes of the Vi editor in Unix. Show how a user is able to switch from
one mode to another. (4 marks)

Page 1 of 3
COSC 224

(g) State the role of the following commands in UNIX. Use an example to illustrate the
command’s usage. (4 marks)

(i) cd
(ii) Passwd
(iii) ls
(iv) adduser

Question Two (20 marks)

(a) Write a shell script for searching files in a given directory to find which files contain the
string “it was then noted”. (8 marks)

(b) Assuming that a file’s current permissions are r-xr-xr--, specify the chmod
expression required to change them to(use both relative and absolute permissions):
(12 marks)
(i) rw-r--r-x
(ii) rwxrw-r--
(iii) ---r--r--
(iv) --x----w-

Question Three (20 marks)

(a) Write a perl script for creating a backup for every file in the current working directory.
Every backup file shall be named “file”_backup where “file” is the file name that you are
backing up. (8 marks)

(b) Write two versions of a file comparison utility fcompare. One version should be
implemented in Shell and the other in Perl. It operates as follows; (12 marks)
% fcompare file1 file2
files are identical

The program should perform basic file checking (file exists) and display appropriate
error messages in the event of file errors e.g.

% fcompare old new


fcompare: File <old> does not exist
%

Question Four [20 marks]


(a) Write a shell program script logic that allows only fred and cate to execute a program,
and only from the terminals tty08 and tty09. (8 marks)

(b) Write a perl program that prompts a user to repeatedly enter an integer number. When
the user enters 0, the program should print the average and the total. The program
should capture all the numbers entered and their total in a file “numbers.txt”.
(12 marks)

Page 2 of 3
COSC 224

Question Five (20 marks)

(a) You have downloaded a file named latest.tex. Explain how you would get this
document formatted and printed. What commands would be used to create and print PDF
and PS versions of the document. (10 marks)

(b) Explain the purpose of each of the following commands, and how to use them, giving
examples: (10 marks)
(i) find
(ii) grep
(iii) file
(iv) gunzip
(v) ssh
(vi) ps
(vii) kill
(viii) who
(ix) ftp
(x) dvips

----------------------------------------------------------------------------------------------------------------

Page 3 of 3

You might also like