Files
2026-03-15 19:51:25 +07:00

4.0 KiB

Operating Systems Lab — Module 1 Answer Key

For Teaching Assistants only. Do not share with students.


1. Navigation

List all files in config/, including hidden ones:

cd sisop_module1_playground
ls -la config/

2. Permissions

Change archive/locked.txt so only the owner can read it:

chmod 400 archive/locked.txt

Verify:

ls -l archive/locked.txt
# Expected: -r-------- 1 <user> ...

Find the "ERROR" line in logs/app.log and save it:

grep "ERROR" logs/app.log > logs/error_only.txt

4. Count

Count files ending in .tmp in data/:

find data/ -name "*.tmp" | wc -l

5. Chaining

List all files in data/ sorted in reverse alphabetical order:

ls data/ | sort -r

6. I/O Redirection

Create info.txt with the current date and username:

echo "$(date) $(whoami)" > info.txt

7. AWK — Print names (Column 2)

awk -F',' 'NR>1 {print $2}' data/users.csv

Expected output:

Budi
Siti
Agus
Dewi
Eko
Sari

8. AWK — Total sum of salaries (Column 4)

awk -F',' 'NR>1 {sum += $4} END {print sum}' data/users.csv

Expected output: 26200


9. AWK — Name and Role of Active users

awk -F',' 'NR>1 && $5=="Active" {print $2, $3}' data/users.csv

Expected output:

Budi Admin
Agus User
Dewi Manager
Sari Admin

10. Bash — scripts/check_dir.sh

#!/bin/bash
if [ -d "$1" ]; then
    echo "Directory '$1' exists."
else
    echo "Directory '$1' does not exist."
fi

Make it executable and test:

chmod +x scripts/check_dir.sh
./scripts/check_dir.sh data/
./scripts/check_dir.sh fakedir/

11. Bash — Fix scripts/hello.sh

Bug: date_now=date assigns the string "date" instead of executing the command.

Fix: Change line 3 to use command substitution:

date_now=$(date)

Corrected hello.sh:

#!/bin/bash
echo "Hello eggboi"
date_now=$(date)
echo "Today is $date_now"

12. Bash — Loop to create 5 files

#!/bin/bash
for i in $(seq 1 5); do
    touch test_${i}.txt
done

13. Cron — Run hello.sh every day at 3:30 AM

30 3 * * * /path/to/sisop_module1_playground/scripts/hello.sh

14. Cron — List all active cron jobs

crontab -l

15. Wildcards — Delete all .bak files in data/

rm data/*.bak

16. Disk Usage — Total size of the lab directory

du -sh sisop_module1_playground/

17. AWK — Name of the person with the highest salary

awk -F',' 'NR>1 {if ($4 > max) {max=$4; name=$2}} END {print name}' data/users.csv

Expected output: Dewi (salary: 7000)


18. Sed — Replace "INFO" with "LOG"

sed 's/INFO/LOG/g' logs/app.log > logs/app_log_replaced.log

19. Processes — Find PID of the current bash session

echo $$

Or alternatively:

ps -p $$

20. Archiving — Create a .tar.gz of logs/

tar -czvf logs.tar.gz logs/

21. Bash — Update, upgrade, and download image

#!/bin/bash

# Update and upgrade the system
sudo apt update && sudo apt upgrade -y

# Create the target directory if it doesn't exist
mkdir -p new_image

# Download an image from a URL into new_image/
# Replace <URL> with the actual image URL
wget -P new_image/ <URL>

#example:
wget -P new_image/ https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/2010-kodiak-bear-1.jpg/1280px-2010-kodiak-bear-1.jpg

# Alternative using curl:
# curl -o new_image/image.jpg <URL>

22. Search — Find secret.txt in maze/

find maze/ -name "secret.txt"

Expected output:

maze/level1_b/level2_d/level3_d/level4_a/secret.txt

Display its contents:

cat maze/level1_b/level2_d/level3_d/level4_a/secret.txt

Expected output:

You found it! The secret message is: sisop2026