Linux/Unix Systems SOLUTION - CP 211
📝 Acknowledgement
Contributor: Anord James
WhatsApp: Degree Programme: BSc CNISE3
Submission Date: 25th September, 2025
Note: We sincerely appreciate your effort in solving and submitting this exam for academic support and reference.
THE UNIVERSITY OF DODOMA
COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION
Department of Computer Science and Engineering
End of Semester One University Examination for the 2022/2023 Academic Year
Course Name: Introduction to Linux/Unix Systems
Paper Code Number: CP 211
Date of Examination: 27th February, 2023
Time: 08:00-11:00
Duration: 3 Hours
Venue(s): CIVE-AUDITORIUM
Sitting Programme(s): BSc. CS2, SE2, BIS2, HIS2, CNISE2, IDIT2, MTA2, IS2, SE2, DCBE2 & CSDFE2
INSTRUCTIONS TO CANDIDATES
i. This examination paper consists of TWO (2) sections with EIGHT (7) questions in FIFTEEN (15) printed pages.
ii. Answer all questions in Section A and any THREE (3) questions in Section B.
iii. The total score for this examination is 100 Marks. Marks are allocated at the end of each question.
iv. ALL responses should be written in the answer book provided. Insert the examination paper into the answer book after the examination. Students should not take any examination paper(s) out of the examination room.
v. All regulations guiding the administration of university examinations apply.
SECTION A: (40 MARKS)
Question One
(a) Choose the most appropriate answer, and fill its corresponding letter or answer into the answer booklet provided. (0.5 Mark Each)
i. What is a Linux Kernel?
A. High-level level of software that acts as a direct interface application program.
B. Human-like language into mathematical symbols.
C. A system software that converts machine language to high-level language.
D. Lowest level of software that can interface with computer hardware.
- ANSWER : D
ii. When do we need to write a Linux Shell program?
A. To monitor the scope of Graphics.
B. Type-checking shell varieties.
C. Keeping all of the names Linus Operating system.
D. Accessing advanced features that can not be accessed through GUI.
- ANSWER: D
iii. What is the scope of local variables in shell scripts?
A. Only within the shell scripts.
B. Only accessible within the brackets of the shell.
C. In the shell scripts.
D. Only accessible within the section of code in which they are declared.
- ANSWER: D
iv. When is the $ used in integer arithmetic operations?
A. Using exact values.
B. Using let operations.
C. Using expr command.
D. Using variables.
- ANSWER: D
v. Which of the following is correct regarding a Linux display server?
A. Provides pixels access services to the drawing program.
B. Provides media access services to the playing program.
C. Minimize pixels access errors.
D. Optimize pixels access error codes.
- ANSWER: A
vi. What is Linux distros?
A. Linux operating system compiled from components developed by various non-open-source projects and programmers.
B. Linux operating system compiled from components developed by various open-source projects and programmers.
C. Linux Operating system packages errors.
D. Package to management optimization errors.
- ANSWER: B
vii. A sub-shell is?
A. A shell child process launched by a shell.
B. A new user console.
C. A small shell analyzer.
D. A shell Token.
- ANSWER: A
viii. ______ is equivalent of do-while in higher level programming language.
A. Until
B. While
C. Switch-Case.
D. For loop.
- ANSWER: A
ix. ______ produces the target code of a shell script.
A. Interpreter
B. Analyzer
C. Compiler
D. Optimizer
- ANSWER: A
x. ______ is a finite set of interpreted languages.
A. C++, C#, C++, Shell, Shell Script.
B. Perl, Python, BASIC, Shell Script.
C. Algol, Java, VB, Shell Script.
D. Java Script, Pascal, Shell Script.
E. Shell Script, Ada, FORTRAN, COBOL
- ANSWER: B
xi. What type of file does each piece of hardware need for the kernel to communicate with it
?
A. Regular file
B. Device driver
C. Directory file
D. Kernel file
- ANSWER: B
xii. What command is used to save and resume editing a file in the vim editor?
A. :w
B. :wq
C. :wql
D. :s
- ANSWER: A
xiii. An employee complains that her home directory has disappeared. Which of the following commands should you use to extract the backup archive of her home directory?
A. tar -cvf home.tar
B. tar -xvf home.tar
C. tar -tvf home.tar
D. tar -evf /home/backup
- ANSWER: B
xiv. Your company has a tight budget, and you have been asked to create tar archives to save space on the backup medium. Which of the following commands enables you to archive home directories and compress them at the same time?
A. tar -czf home.tar.gz /home
B. gzip -v /home
C. bzip2 -v /home
D. tar -cvf home.tar.gz /home
- ANSWER: A
xv. Which type of partition is installed as part of the Linux boot sector and supports a maximum of four partitions?
A. Primary partition
B. Logical partition
C. Extended partition
D. Swap partition
- ANSWER: A
xvi. Which of the following commands can be used to find file system information?
A. mkfs
B. fsck
C. dumpe2fs
D. mount
- ANSWER: C
(b) After you use the ls command, the following files are displayed:
file1 file2 file3 file.a file.b file.c files
List the files displayed with each of the following options:
i. ls f*
- ANSWER:
file1 file2 file3 file.a file.b file.c files
ii. ls file?
- ANSWER:
file1 file2 file3
iii. ls file[a-c]
- ANSWER:
file.a file.b file.c
iv. ls file[1-3]
- ANSWER:
file1 file2 file3
Question Two
Match the item in List A with its corresponding item in List B. (1 Mark Each)
List A
i. Multics Shell Script.
ii. System Variables
iii. Let and Expr
iv. Daemon
v. X.org
vi. Debian
vii. Repeating application programs
viii. wget command
ix. vim, emacs, nano
x. Targeted Code
List B
A. Expected output of the shell scripts.
B. First shell like program.
C. Accessible through the program.
D. One of the Linux distros.
E. Represent the intermediate code.
F. Linux background process.
G. Common Display Server.
H. Looping Commands.
I. Shell editors
J. Rewriting code in shell.
K. A non-terminal scripts whose output is used in displaying scripts.
L. An automation of Linux parser.
Answers:
i - B
ii - C
iii - H
iv - F
v - G
vi - D
vii - H
viii - J
ix - I
x - A
Question Three
Fill the blanks with most appropriate answer, and write it in the answer booklet provided. (1 Mark Each)
i. /etc/passwd
is the PATH of password file located Linux.
ii. 255
maximum length for any file name under LINUX.
iii. Insert mode
is an edit mode in vi editor.
iv. Daemon
runs continuously as a background process and wakes up to handle periodic service requests.
v. Read, Write, Execute
types file permission that is given to a file.
vi. Stack
temporary amount of memory space on Linux that is created to allow a certain program to run smoothly.
vii. LD_LIBRARY_PATH
environment variable used for debugging a new library or a non-standard library.
viii. ProFTPD or vsftpd
a service that acts both as web and FTP servers on a Linux server.
ix. umask
user file creation mode.
x. Linux kernel is a monolithic
kernel whereby entire operating system is working in kernel space.
Question Four
The following is a list of modifications that you can make with the usermod command: Show how each can be performed. (1 Mark Each)
i. Add the user to a supplementary group
usermod -aG groupname username
ii. Change the user’s comment field in /etc/passwd
usermod -c "New Comment" username
iii. Change the user’s home directory
usermod -d /new/home/directory username
iv. Set an account expiry date
usermod -e YYYY-MM-DD username
v. Remove an expiry date
usermod -e "" username
or usermod -e 0 username
vi. Change a user’s login name (username)
usermod -l newusername oldusername
vii. Lock/unlock a user’s account
Lock: usermod -L username
Unlock: usermod -U username
viii. Move the contents of a user’s home directory
usermod -m -d /new/home username
ix. Change a user’s login shell
usermod -s /bin/bash username
x. Change a user’s ID
usermod -u newUID username
SECTION B: (60 MARKS)
Attempt THREE (3) out of FOUR (4) questions provided.
Question Five
Briefly argue for or argue against the following statements about a Linux Display Server: (5 Marks Each)
(a) System program that high-level programs for displaying services.
Answer: Correct. A display server provides a graphical interface for high-level programs.
(b) System program that application program into kernel like program.
Answer: Incorrect. A display server is a user-space program, not kernel-like.
(c) A core of Linux operating system.
Answer: Incorrect. It is not a core component; it can be replaced or removed.
(d) A system program that processes request on access of pixels.
Answer: Correct. It handles pixel-level drawing requests.
Question Six
(a) It’s a matter of trust that the user will change their password when you provide them with an initial password. Sysadmins who regularly audit their user’s passwords realize that this “honor system” level of trust doesn’t work 100 percent of the time. How can you audit user accounts, that is, to check their password status? (3 Marks)
Answer:
- Use
chage -l username
to check password expiration details. - Review
/etc/shadow
for last password change dates. - Use tools like
awk -F: '{print $1,$5}' /etc/shadow
to list users and password change dates. - Implement password policy audits with tools like
pwck
orlibuser
.
(b) In addition to a regular forced change of passwords, you can also set a minimum change period. For example, you can make some settings to user accounts to force a password change every number of days (e.g., 60 days) with a minimum number of days between password changes to one. Setting a minimum number of days ensures that users don’t change their passwords ten times (or whatever the number of the system’s remembered passwords is set to) to reset it to their original password, which amounts to no net password change. How can you implement such settings? (6 Marks)
Answer:
- Use
chage -m 1 username
to set minimum days between changes. - Use
chage -M 60 username
to set maximum password age. - Edit
/etc/login.defs
to setPASS_MIN_DAYS 1
andPASS_MAX_DAYS 60
. - Use
passwd -n 1 -x 60 username
for the same effect.
(c) You have been tasked to find all files on your filesystem that are larger than 10 MB in size. What command would you use to easily find those files? (4 Marks)
Answer:
find / -type f -size +10M
(d) Four science instructors at CNMS College ask you whether they can access a particular log file from their home directories. They explain that they update a log file in the /workgry/project directory weekly, and they don’t want to change out of their home directories every time they want to view or edit the file. In addition, they want the log file in their home directories to be called mijournal. You need to create a link to the log file so that each instructor can access the file from his or her home directory, using the following criteria:
- Scientist 1: Michio | Home directory:
/home/michio
- Scientist 2: Neil | Home directory:
/home/neil
- Scientist 3: Marty | Home directory:
/home/marty
- Scientist 4: Ellen | Home directory:
/home/ellen
The log file is called sci.journal
, and it’s in the /workgry/project
directory. (7 Marks)
Answer:
ln -s /workgry/project/sci.journal /home/michio/mijournal
ln -s /workgry/project/sci.journal /home/neil/mijournal
ln -s /workgry/project/sci.journal /home/marty/mijournal
ln -s /workgry/project/sci.journal /home/ellen/mijournal
Question Seven
(a) System administrators agree that managing groups is much easier and more efficient than managing users. Group management. Write five uses of group management in Linux systems. (2.5 Marks)
Answer:
- Simplify permission assignment to files/directories.
- Ease user management by grouping users with similar access needs.
- Enhance security by restricting access to sensitive data.
- Automate tasks using group-based cron jobs or scripts.
- Improve auditing by tracking group-based activities.
(b) When you create a new user account, the system assigns the user a user ID (UID) and a primary group ID (GID). They can be the same sequential number but that isn’t always the case. For example, for the account created as Juma Daudi, can have UID as 1007 and the GID as 1007. Juma’s primary GID is 1007 but he might also work in an area of the company, such as IT, Engineering, or Application development that requires him to have access to a group-owned directory. In this, Juma works in the Engineering department as an associate engineer. The Engineering department’s shared directory GID is 8020.
(i) Show how to grant Juma access to that group’s shared directory. (1.5 Marks)
Answer:
usermod -aG 8020 juma
(ii) If the Administrators are to be the new owners of the directory, how will you accomplish that? (1.5 Marks)
Answer:
chown -R administrators:administrators /path/to/directory
(c) (i) Identify the components or fields of passwd file. (1.5 Marks)
Answer:
Username:Password:UID:GID:Comment:Home Directory:Shell
(ii) Write awk command to display the user and his/her home path. (4.5 Marks)
Answer:
awk -F: '{print $1, $6}' /etc/passwd
(iii) Write sed command to replace a ’/’ with a ’*’ from the home path of a particular user. (4.5 Marks)
Answer:
sed -i 's/\//*/g' /etc/passwd
(d) As you are creating a shell script, you recognize that you are writing these four lines of code over and over again:
echo "Error in processing file, $1."
echo "Check that the $1 file exists and contains data."
echo "This script will now exit..."
exit
Properly write a function named errorMessage that will allow you to turn these four lines of code into a single line (except for the function declaration) throughout the script. (4 Marks)
Answer:
errorMessage() {
echo "Error in processing file, $1."
echo "Check that the $1 file exists and contains data."
echo "This script will now exit..."
exit 1
}
Question Eight
(a) Write a shell script to automate renaming of files and their correspond directories. (7 Marks)
Answer:
#!/bin/bash
# Shell script to rename files and directories
echo "Enter prefix to add to files and directories:"
read prefix
# Loop through all items in current directory
for item in *; do
if [ -e "$item" ]; then
mv "$item" "${prefix}_${item}"
fi
done
echo "Renaming completed."
(b) The following are some of the common bash/Linux command line symbols. For each symbol, describe its meaning when used in the command line interface and an example of its use in any command. (7 Marks)
Symbol | Meaning | Example |
---|---|---|
~ | Home directory | cd ~ |
* | Wildcard | ls *.txt |
& | Run in background | firefox & |
&& | Logical AND | cmd1 && cmd2 |
\ | Escape character | echo "Hello\nWorld" |
$(()) | Arithmetic expansion | echo $((5+3)) |
^$ | Start/end of line | grep "^start" file |
# | Comment | # This is a comment |
| | Pipe | ls | grep txt |
> | Output redirect | ls > file.txt |
< | Input redirect | cat < file.txt |
>> | Append redirect | echo "text" >> file.txt |
… | Parent directory | cd .. |
abc$ | End of line | grep "end$" file |
(c) The University of Dodoma has admitted four students, namely Kipanya, Matonya, Sechelela and Hawa, to join a two-month Linux Administration short course. During this period, they will need to access Labs, Halls (or dormitories), Library and Stationeries. Assuming that the mentioned resources have been configured as groups in Linux systems:
(i) Use a for loop to add the students to the respective groups, within a single -line commands.
Answer:
for student in Kipanya Matonya Sechelela Hawa; do
usermod -aG labs,halls,library,stationeries $student
done
(ii) Provide three options with sample outputs to verify that the students have been added to the groups.
Answer:
groups studentname
getent group labs
id studentname
END OF EXAMINATION PAPER