0% found this document useful (0 votes)
10 views14 pages

OS Lab Manual

Lab manual for ubuntu

Uploaded by

teweldeananya24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views14 pages

OS Lab Manual

Lab manual for ubuntu

Uploaded by

teweldeananya24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

UNIX Operating System 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

Comparison Between UNIX and Windows Operating Systems

Aspect UNIX Windows


Developed at AT&T Bell Labs in the
Origin Developed by Microsoft, first released in 1985.
1970s.
Monolithic kernel (in most UNIX-like Hybrid kernel (a mix of monolithic and
Kernel Type
systems). microkernel approaches).

Primarily command-line interface Graphical User Interface (GUI) as primary; CLI


User Interface
(CLI), though GUIs are available. (Command Prompt, PowerShell) secondary.

Hierarchical structure with directories Drive-letter-based hierarchy (e.g., C:\, D:\)


File System
like /home, /bin, /etc. with NTFS as standard.

Highly customizable; open-source Limited customization; closed source with


Customizability
derivatives (e.g., Linux, FreeBSD). proprietary architecture.

Strong built-in security, file


Good security but often targeted by malware
Security permissions, and user/group
due to larger market share.
management.

Efficient resource management, Can be resource-intensive, especially with GUI-


Performance
suitable for servers and multitasking. heavy applications.

Preferred for servers, programming, Dominant in personal computing and enterprise


Usage Domains
and academic purposes. desktop environments.

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

Aspect UNIX Windows

Open-source (varies by distribution);


Licensing Proprietary licensing from Microsoft.
some proprietary (e.g., macOS).

Command-Line Interface (CLI)


The CLI is a text-based interface that allows users to interact directly with the operating system
through commands. UNIX systems are particularly known for their robust CLI environment,
which includes shells like bash, zsh, and csh. The CLI provides numerous advantages:

 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 Content and Commands

Lab Session 1:

1. Use pwd to display the current directory.


2. Navigate to different directories using cd.
3. Create new files with touch and verify them with ls.

1.1 Navigating the File System


Command: pwd

 Definition: Displays the current working directory.

3|Page
UNIX Operating System Lab Manual

 Usage:
$ pwd
Terminal Output:
/home/user

Command: cd

 Definition: Changes the current directory.


 Usage:
$ cd /path/to/directory
 Terminal Output:
$ cd Documents

$ 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:

drwxr-xr-x 2 user group 4096 Oct 26 10:15

Documents -rw-r--r-- 1 user group 120 Oct 26 09:12 file.txt

Command: touch

 Definition: Creates an empty file.


 Usage:

$ touch newfile.txt

4|Page
UNIX Operating System Lab Manual

Chapter 2

File Manipulation Commands


Objectives: At the end of this chapter, the students should be able to:
 Manipulate files (copy, move, rename, and delete).
 Understand file permissions and modify them as needed.

Introduction
File management in UNIX involves commands that control file content, structure, and
permissions, which are key for maintaining security and organization.

Lab Content and Commands

Lab Session 2:
1. Use cp to copy files to a new location.
2. Rename files with mv.
3. Delete files with rm.

2.1 Copying, Moving, and Renaming Files

 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

 Definition: Moves or renames files and directories.

5|Page
UNIX Operating System Lab Manual

 Usage:

$ mv oldname.txt newname.txt

2.2 Deleting Files and Directories

 Command: rm
o Definition: Deletes files.
o Usage:

$ rm file.txt

o Terminal Output:
$ ls
file.txt not found

2.3 copying Files


 Command: cat
o Definition: The cat command (short for "concatenate") is used to view the
contents of files, join multiple files, or create new files.
o Usage:
cat [options] [file...]

2.3.1 Display Contents of a Single File

o Usage:
cat filename
o Example:
$ cat notes.txt
o Explanation: Displays the contents of notes.txt.

2.3.2 Concatenate Multiple Files

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.

2.3.3 Display Line Numbers

o Usage:
cat -n filename
o Example:
$ cat -n notes.txt
o Explanation: Displays notes.txt with each line numbered.

2.3.4 Create a New File with cat


o Usage:
cat > newfile.txt
o Example:
$ cat > my_notes.txt
o Explanation: Creates a new file my_notes.txt and lets you type content directly
into the terminal. Press Ctrl + D to save.

2.3.5 Display Content with End of Line Markers


o Usage:
cat -E filename
o Example:
$ cat -E notes.txt
o Explanation: Shows the end of each line in notes.txt by marking it with $.
2.4 finding Files

2.4.1 Find Files by Name


o Usage:
find /path/to/search -name "filename"
o Example:

7|Page
UNIX Operating System Lab Manual

$ find /home/user -name "document.txt"


o Explanation: Searches for document.txt in the /home/user directory.

2.4.2 Find Files by Type


o Usage:
find /path/to/search -type f
o Example:
$ find /home/user/Documents -type f
o Explanation: Lists all files (-type f) in the specified directory.

2.4.3 Find Directories by Type

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.

2.4.4 Find Files by Size

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.

2.4.5 Find Files Modified within the Last N Days

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

2.4.6 Execute Commands on Found Files

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

Chapter 3: Directory Management

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.

Lab Content and Commands


Lab Session 3:
1. Create directories with mkdir.
2. Remove empty directories using rmdir.

3.1 Creating and Removing Directories


 Command: mkdir
o Definition: Creates a new directory.
o Usage:

$ 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

Chapter 4: File Permissions and Ownership

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 Content and Commands

Lab Session 4:

1. View and modify file permissions with chmod.


2. Change file ownership using chown.

4.1 Viewing and Modifying Permissions

 Command: chmod
o Definition: Changes file permissions.
o Usage:

$ chmod 755 file.txt

4.2 Changing Ownership

 Command: chown
o Definition: Changes file ownership.
o Usage:

$ chown user:group file.txt

11 | P a g e
UNIX Operating System Lab Manual

Chapter 5: Text Editing and Viewing

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.

Lab Content and Commands


Lab Session 5:
1. Display file contents using cat.
2. Edit files with nano or vim.

5.1 Viewing Text Files

 Command: cat
o Definition: Concatenates and displays file contents.
o Usage:

$ cat file.txt

5.2 Editing Text Files

 Command: nano or vim


o Definition: Opens a text editor.
o Usage:

$ nano file.txt

12 | P a g e
UNIX Operating System Lab Manual

Chapter 6: Process Management

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.

Lab Content and Commands


Lab Session

1. Use ps to view active processes.


2. Terminate a process with kill.

6.1 Viewing Processes

 Command: ps
o Definition: Displays current processes.
o Usage:

$ ps –aux

6.2 Killing Processes

 Command: kill
o Definition: Terminates processes by PID.
o Usage:

$ kill 1234

Chapter 7: Shell Scripting Basics

Objectives

13 | P a g e
UNIX Operating System Lab Manual

 Understand the basics of shell scripting.


 Write simple scripts to automate tasks.

Introduction

Shell scripting automates repetitive tasks, enhancing productivity in UNIX.

Lab Content and Commands

Lab Session

1. Create a shell script.


2. Execute the script and observe output.

7.1 Writing a Basic Script

 Command: echo
o Definition: Prints text to the screen.
o Usage:

$ echo "Hello, UNIX!"

Example Script:

#!/bin/bash

echo "This is my first shell script"

14 | P a g e

You might also like