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
- ls / cd / pwd
- List, change and show directories
- cp / mv / rm
- Copy, move, delete files
- mkdir / rmdir
- Create and remove directories
- grep / find / sort
- Search text, find files, sort lines
- ps / kill
- View and stop processes
- df / du
- Disk space used and free
Topic 1
Installing operating systems
- 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.
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.
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
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 partitionsTopic 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
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 fieldTopic 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
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.
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.
