Unit 1: OS installation, Linux commands and shell scripting
Software Lab-IV (Operating Systems) notes · PTU syllabus (BSIT305)
On this page
Unit summary
This lab covers practical operating system skills: installing operating systems, virtualisation and installing an OS on a virtual machine, Linux file, directory and disk commands, process management, text-processing commands, and shell programming — conditions, loops, case statements, parameters and variables — to automate system tasks and print reports.
After this unit you can
- Install an OS on a physical or virtual machine
- Use Linux file, directory, disk and process commands
- Use grep, find and sort for text processing
- Write shell scripts with conditions, loops, case and parameters
PTU syllabus topics
- Installation of various operating systems
- virtualization and installing an OS on a virtual machine
- Linux file/directory commands (cd, ls, cp, mkdir, rmdir, cat)
- disk space commands
- process management (pipes, background processing, priority, ps, kill)
- text-processing commands (grep, find, sort)
- shell programming basics — conditional and looping statements
- case statements
- parameter passing
- shell variables
- automating system tasks and report printing
Topic 1
Installing operating systems
Installing an OS involves preparing bootable media, booting from it, partitioning the disk, choosing settings and creating a user account.
- 1
Download the ISO image
- 2
Create bootable USB (Rufus, Etcher)
- 3
Boot from USB (change boot order in BIOS/UEFI)
- 4
Choose language, keyboard, installation type
- 5
Partition the disk
Root (/), swap, home; or use entire disk
- 6
Set time zone, user name and password
- 7
Install and reboot
- Windows installation: boot from media, select edition, accept licence, custom install, partition, set user, updates and drivers.
- Dual boot: install Windows first, then Linux; GRUB boot loader offers a choice at start-up.
Example
Dual boot: a student installs Ubuntu alongside Windows by shrinking the Windows partition, booting from the Ubuntu USB, choosing 'Install alongside Windows', and later selecting the OS from the GRUB boot menu at start-up.
Exam tip
Back up data before partitioning a disk.
Topic 2
Virtualisation and installing an OS on a virtual machine
- Virtualisation: running multiple operating systems on one physical machine through a hypervisor — Type 1 (bare metal: VMware ESXi, Hyper-V) and Type 2 (hosted: VirtualBox, VMware Workstation).
- 1
Install VirtualBox
- 2
New VM — name, type Linux, version Ubuntu (64-bit)
- 3
Allocate RAM (2–4 GB) and CPUs
- 4
Create a virtual hard disk (VDI, 20+ GB, dynamically allocated)
- 5
Attach the Ubuntu ISO to the optical drive
- 6
Start the VM and install
- 7
Install Guest Additions for better display and shared folders
- Benefits: safe experimentation, snapshots, running multiple OSes, testing.
Example
Practising safely: in VirtualBox, a student creates a virtual machine with 2 GB RAM and a 20 GB virtual disk, attaches the Ubuntu ISO, and installs Linux inside it — without changing the real Windows installation.
Exam tip
Type 1 hypervisors run on hardware (VMware ESXi, Hyper-V); type 2 run on a host OS (VirtualBox, VMware Workstation).
Topic 3
Linux file and directory commands
bashpwd # print working directory
ls -l # long listing; ls -a shows hidden files
cd /home/student # change directory; cd .. goes up
mkdir lab4 # make directory
rmdir lab4 # remove empty directory
cp a.txt b.txt # copy; cp -r dir1 dir2 copies folders
mv b.txt notes.txt # move or rename
rm notes.txt # remove file; rm -r dir removes folder
cat a.txt # display; cat > new.txt creates (Ctrl+D to end)
chmod 755 run.sh # change permissionsTopic 4
Disk space commands
These commands help find which file systems and folders use the most space.
bashdf -h # free and used space on file systems
du -sh lab4 # space used by a directory
free -h # memory usage
lsblk # block devices and partitionsExample
Finding what fills the disk: df -h shows the root partition is 92% full; du -sh /home/* shows one user's folder uses 30 GB; du -sh * | sort -h inside it reveals a large video folder to clean up.
Exam tip
-h means human-readable sizes (K, M, G).
Topic 5
Process management
bashps -ef # list all processes
top # live view of processes
sleep 100 & # run in background (&)
jobs # list background jobs; fg %1 brings to foreground
nice -n 10 ./job.sh # start with lower priority
renice 5 -p 1234 # change priority of a running process
kill 1234 # terminate process 1234; kill -9 forces
ls -l | wc -l # pipe: count lines of outputTopic 6
Text-processing commands
Linux text tools such as grep, cut, sort, uniq, wc, head, tail and sed can be combined with pipes to process files quickly.
bashgrep "error" app.log # lines containing error
grep -i -n "linux" notes.txt # ignore case, show line numbers
find /home -name "*.c" # find C files
find . -size +1M # files larger than 1 MB
sort marks.txt # sort lines; sort -n numeric; sort -r reverse
sort -t, -k2 -n data.csv # sort CSV by 2nd fieldExample
Counting errors: grep -c "error" app.log counts lines with 'error'; cut -d, -f2 marks.csv | sort | uniq -c counts how many students have each grade in column 2.
Exam tip
Combine commands with | (pipe) — each command's output becomes the next one's input.
Topic 7
Shell programming basics
bash#!/bin/bash
# Variables, parameters and conditions
name=$1 # first command-line parameter
echo "Hello $name, you passed $# arguments"
if [ $2 -gt 50 ]; then
echo "Pass"
else
echo "Fail"
fi
# Loops
for i in 1 2 3 4 5; do echo "Square of $i is $((i * i))"; done
n=1
while [ $n -le 3 ]; do echo "Count $n"; n=$((n + 1)); done
# Case statement
read -p "Enter choice (1-3): " ch
case $ch in
1) date ;;
2) df -h ;;
3) who ;;
*) echo "Invalid" ;;
esac- Run with: chmod +x script.sh then ./script.sh Riya 72.
Topic 8
Automating system tasks and report printing
Shell scripts automate repeated tasks; cron runs them on a schedule.
bash#!/bin/bash
# Daily system report
report=report_$(date +%F).txt
{
echo "System report for $(hostname) on $(date)"
echo "--- Disk usage ---"; df -h
echo "--- Memory ---"; free -h
echo "--- Logged-in users ---"; who
echo "--- Top 5 processes by memory ---"; ps aux --sort=-%mem | head -6
} > "$report"
echo "Report saved to $report"- Scheduling with cron: crontab -e and add a line such as 0 9 * * * /home/student/report.sh to run at 9 a.m. daily.
Example
Scheduling a daily report: make the script executable with chmod +x report.sh, then add 0 18 * * * /home/user/report.sh with crontab -e to run it every day at 6 pm.
Exam tip
The five cron fields are minute, hour, day of month, month and day of week.
Key terms
- Hypervisor
- Software that runs virtual machines
- Shell
- Command interpreter (bash)
- Pipe
- Passes output of one command as input to another
- Background process
- Process running without holding the terminal
- cron
- Scheduler for repetitive tasks
Quick revision
- OS installation steps; partitions; dual boot.
- Type 1 and Type 2 hypervisors; VirtualBox set-up.
- ls, cd, mkdir, rmdir, cp, mv, rm, cat, chmod; df, du, free.
- ps, top, &, jobs, fg, nice, kill; grep, find, sort.
- Shell scripts: variables, $1 and $#, if, for, while, case; report automation and cron.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Distinguish Type 1 and Type 2 hypervisors.
- Q2.What does df -h show?
- Q3.How do you run a process in the background?
- Q4.Write a command to find all .txt files in the current directory.
- Q5.What does $# represent in a shell script?
- Q6.What is the use of crontab?
Long-answer questions
- Q1.Explain the steps to install Linux on a virtual machine.
- Q2.Explain Linux file, directory and process management commands with examples.
- Q3.Write a shell script using if, for, while and case statements.
- Q4.Write a shell script to generate a system report and schedule it with cron.
Stuck on this unit?
Message SBS on WhatsApp for help with Software Lab-IV (Operating Systems), or to ask about studying B.Sc IT at Synetic.
