COSC 224 Exam (1) GGH
COSC 224 Exam (1) GGH
CHUKA UNIVERSITY
UNIVERSITY EXAMINATIONS
(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)
(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
(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-
(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.
(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
(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