OS Lab Manual
OS Lab Manual
Chapter 1
Introduction to UNIX
Basic Commands
Objectives: At the end of this chapter, the students should be able to:
Understand UNIX basics, structure, and key characteristics.
Learn fundamental commands for navigation and file management.
Get familiar with the command-line interface (CLI).
Introduction
UNIX is one of the most influential operating systems in computing history. It was first developed
in the 1970s at AT&T's Bell Labs and has since become the foundation for many modern operating
systems, such as Linux and macOS. Its enduring popularity stems from several key characteristics:
Powerful: UNIX supports multitasking and multi-user capabilities, allowing multiple processes
and users to operate simultaneously. This made it ideal for servers, development environments,
and enterprise systems.
Reliable: Known for its stability, UNIX can run for extended periods without crashes or the need
for frequent reboots. This reliability is essential for critical systems like servers, network
infrastructure, and embedded systems.
Simplicity: The design philosophy of UNIX emphasizes small, modular programs that perform
one task exceptionally well. This "do one thing well" approach makes UNIX systems easier to
understand and maintain.
Flexibility: UNIX is highly customizable and supports a wide variety of use cases. It is portable,
meaning it can be adapted to run on different hardware architectures.
1|Page
UNIX Operating System Lab Manual
Software Rich CLI-based tools, fewer GUI- Extensive GUI-centric software, including
Availability centric applications. games and productivity apps.
Many free and open-source Requires purchase of a license for Windows
Cost
distributions (e.g., Linux). editions.
Frequent, community-driven updates Regular updates managed by Microsoft
Updates
in open-source versions. (Windows Update).
Robust networking tools (ssh, scp, Good networking features, user-friendly, but
Networking
etc.), popular in servers. may need third-party tools.
Steeper learning curve, especially for
Ease of Use User-friendly, designed for non-technical users.
CLI-heavy use.
Linux, FreeBSD, macOS (UNIX-
Examples Windows 10, Windows 11, Windows Server.
based).
2|Page
UNIX Operating System Lab Manual
Control: Users can perform a wide range of tasks by executing commands, from basic file
manipulations to managing processes and configuring the system.
Efficiency: For advanced users, the CLI allows tasks to be completed much faster than
through graphical interfaces, especially when combined with scripts or chained commands.
Flexibility: The CLI offers powerful tools for automating repetitive tasks using shell
scripting. Commands can also be combined using pipelines (|) and redirection operators (>
and <) to create complex workflows.
Precision: Unlike GUI tools, which might abstract some operations, the CLI provides fine-
grained control, making it ideal for troubleshooting and configuration.
The CLI provides control over the operating system, allowing for efficient interaction with files,
directories, processes, and more.
Lab Session 1:
3|Page
UNIX Operating System Lab Manual
Usage:
$ pwd
Terminal Output:
/home/user
Command: cd
$ pwd
/home/user/Documents
1.2 File Management
Command: ls
o Definition: Lists files and directories within a directory.
o Usage:
$ ls -l
o Terminal Output:
Command: touch
$ touch newfile.txt
4|Page
UNIX Operating System Lab Manual
Chapter 2
Introduction
File management in UNIX involves commands that control file content, structure, and
permissions, which are key for maintaining security and organization.
Lab Session 2:
1. Use cp to copy files to a new location.
2. Rename files with mv.
3. Delete files with rm.
Command: cp
o Definition: Copies files and directories.
o Usage:
$ cp source.txt destination.txt
o Terminal Output:
$ ls
source.txt destination.txt
Command: mv
5|Page
UNIX Operating System Lab Manual
Usage:
$ mv oldname.txt newname.txt
Command: rm
o Definition: Deletes files.
o Usage:
$ rm file.txt
o Terminal Output:
$ ls
file.txt not found
o Usage:
cat filename
o Example:
$ cat notes.txt
o Explanation: Displays the contents of notes.txt.
o Usage:
cat file1 file2 > combinedfile
6|Page
UNIX Operating System Lab Manual
o Example:
$ cat part1.txt part2.txt > full_document.txt
o Explanation: Combines part1.txt and part2.txt into a new file called
full_document.txt.
o Usage:
cat -n filename
o Example:
$ cat -n notes.txt
o Explanation: Displays notes.txt with each line numbered.
7|Page
UNIX Operating System Lab Manual
o Usage:
find /path/to/search -type d
o Example:
$ find /home/user -type d
o Explanation: Lists all directories (-type d) in the /home/user path.
o Usage:
find /path/to/search -size +1M
o Example:
$ find /var/log -size +10M
o Explanation: Finds all files larger than 10 MB in /var/log.
o Usage:
find /path/to/search -mtime –N
o Example:
$ find /home/user -mtime -7
o Explanation: Finds files modified in the last 7 days.
8|Page
UNIX Operating System Lab Manual
o Usage:
find /path/to/search -name "*.txt" -exec cat {} \;
o Example:
$ find /home/user -name "*.log" -exec cat {} \;
o Explanation: Finds all .log files and displays their content using cat.
9|Page
UNIX Operating System Lab Manual
Objectives: At the end of this chapter, the students should be able to:
Create, delete, and manage directories.
Learn about recursive operations and directory structures.
Introduction
Directories organize files hierarchically in UNIX. Managing directories effectively is crucial for
maintaining a logical file system.
$ mkdir newdir
o Terminal Output:
$ ls
Newdir
Command: rmdir
o Definition: Removes empty directories.
o Usage:
$ rmdir newdir
10 | P a g e
UNIX Operating System Lab Manual
Objectives: At the end of this chapter, the students should be able to:
Understand file permissions and how to modify them.
Learn about user and group ownership.
Introduction
UNIX file permissions control read, write, and execute access to files and directories, which are
fundamental for system security.
Lab Session 4:
Command: chmod
o Definition: Changes file permissions.
o Usage:
Command: chown
o Definition: Changes file ownership.
o Usage:
11 | P a g e
UNIX Operating System Lab Manual
Objectives: At the end of this chapter, the students should be able to:
View and edit text files from the command line.
Learn to use basic text manipulation commands.
Introduction
Text editing is essential for configuration, scripting, and data processing in UNIX.
Command: cat
o Definition: Concatenates and displays file contents.
o Usage:
$ cat file.txt
$ nano file.txt
12 | P a g e
UNIX Operating System Lab Manual
Objectives: At the end of this chapter, the students should be able to:
Manage processes and understand system resource usage.
Learn commands to monitor and control active processes.
Introduction
Process management allows you to monitor, prioritize, and terminate processes as needed for
system optimization.
Command: ps
o Definition: Displays current processes.
o Usage:
$ ps –aux
Command: kill
o Definition: Terminates processes by PID.
o Usage:
$ kill 1234
Objectives
13 | P a g e
UNIX Operating System Lab Manual
Introduction
Lab Session
Command: echo
o Definition: Prints text to the screen.
o Usage:
Example Script:
#!/bin/bash
14 | P a g e