OSlab Ishi
OSlab Ishi
Architecture of Linux:
Linux, as an operating system kernel, is designed to be highly modular
and portable, allowing it torun on a wide range of hardware
architectures. Its architecture can be broken down into several key
components:
1. Kernel:
The Linux kernel is the core of the operating system. It manages
hardware resources, provides essential services, and handles
communication between software and hardware. Itis responsible
for tasks like process management, memory management, device
drivers, andsystem calls.
2. User Space:
The user space is where user-level programs and applications run.
It includes various systemlibraries and utilities that interact with the
kernel through system calls. User space is isolatedfrom the kernel
to ensure stability and security.
3. System Libraries:
Linux relies on a set of system libraries, such as the GNU C Library
(glibc), to provide a standardized interface for user programs to
interact with the kernel. These libraries abstractlow-level operations
and offer higher-level functions that make development easier.
4. Shell:
The shell is the user interface for interacting with the Linux system.
It interprets user commands and communicates with the kernel and
system utilities to execute tasks. Popularshells include Bash, Zsh,
and Fish.
5. File System:
Linux supports various file systems, including ext4, XFS, and Btrfs,
for storing and organizing data on storage devices. It abstracts
access to these file systems through a unifiedfile hierarchy.
6. Device Drivers:
Device drivers are modules that allow the kernel to communicate
with hardware devices, such as graphics cards, network adapters,
and storage controllers. Linux has a vast collectionof device drivers
to support a wide range of hardware.
7. Networking Stack:
Linux includes a robust networking stack that supports various
network protocols, including TCP/IP. It provides the necessary tools
for networking configuration and communication.
8. Security Model:
Linux offers security features like user and group permissions,
access control lists (ACLs), and mandatory access controls (e.g.,
SELinux and AppArmor) to protect system resources and data.
9. Init System:
Traditionally, Linux used init as its init system to manage the boot
process and system services. However, many distributions have
transitioned to alternative init systems like systemd.
11 Package Management:
Linux distributions often include package managers (e.g., APT,
YUM, Pacman) to facilitatethe installation, update, and removal of
software packages.
12 Graphical User Interface (Optional):
While not a core component of Linux, many Linux distributions
include desktop environments (e.g., GNOME, KDE, Xfce) and
window managers to provide a graphical userinterface.
Features Of Linux
Linux is an open-source operating system known for its versatility, security,
and robustness. Hereare some of its key features:
Advantage of Linux
Help
Provides basic information and usage tips for shell built-in commands,
typically giving quick guidance.
What is
Displays a brief description of a command, summarizing its purpose and
functionality.
Apropos
Searches the manual page names and descriptions for keywords, helping
users find relevant commands or topics.
Practical 3
To understand basic directory navigation commands like cat, cd, mv,
cp, rm, mkdir, rmdir, file, pwd commands
mkdir
Creates new directories, helping to organize files into structured folders.
Cd
Changes the current directory, enabling navigation through the file system.
cat
Displays the content of files, allowing users to view text quickly in the
terminal.
mv
Moves or renames files and directories, allowing for organization and
management of files.
cp
Copies files and directories, creating duplicates while keeping the original
intact.
File
Determines and displays the type of a specified file, providing insight into its
format.
Pwd
Prints the current working directory, showing the full path to the current
location in the file system.
rm
Deletes files and directories, permanently removing them from the file
system.
rmdir
Practical 4
To understand commands like- date, cal, echo, bc, ls, who, whoami,
hostname, uname, tty, alias
date
Displays or sets the system date and time, allowing users to check or
configure time settings.
cal
Shows a calendar for a specified month or year, providing an easy way to
view dates.
echo
Outputs text or variables to the terminal, commonly used for displaying
messages or debugging.
bc
An arbitrary precision calculator language, enabling users to perform
mathematical calculations directly in the terminal.
ls
Lists files and directories in the current location, providing details like size and permissions.
who
Displays a list of users currently logged into the system, showing their
login names and terminals.
Whoami
Returns the username of the current user, identifying who is logged into the
session.
hostname
Displays the name of the current system, useful for network identification
and configuration.
uname
Provides system information, such as the kernel name, version, and
hardware architecture.
tty
Displays the file name of the terminal connected to the session, indicating
the terminal interface in use.
aliase
Creates shortcuts for commands, allowing users to define simpler or
customized command names for frequent use
Practical 5
To understand vi basics, Three modes of vi Editor, how to write,
save, execute a shell script in vi editor.
The vi editor operates in three primary modes:
1. Normal Mode: This is the default mode, where you can
navigate the text, delete characters, and execute commands.
You enter this mode by pressing Esc.
2. Insert Mode: This mode allows you to input text. You can enter it by
pressing i for insert or a to append. To return to Normal Mode, press
Esc.
3. Command-Line Mode: Accessed from Normal Mode by typing :.
Here, you can save, quit, or perform other commands.
To write and save a shell script in vi, first, open a new file (e.g., vi
script.sh). Switch to Insert Mode to write your script. After editing, return
to Normal Mode and type :w to save. Use :x to save and exit, or :q! to
exit without saving. To execute the script, use the command line to run
bash script.sh
PROGRAM
11
Write a basic shell directory to display the table of a number.
if [ -z "$1" ]; then
echo "Usage: $0
<number>" exit 1
fi
number=
$1
echo "Multiplication Table for
$number" for i in {1..10}; do
echo "$number x $i = $
((number * i))" done
OUTPUT
Practical 12
Write a basic shell script to input character from the user and
check whether it is an uppercase, lowercase or a digit.
read -p "Enter a
character: " char if [ $
{#char} -ne 1 ]; then
echo "Please enter a single
character." exit 1
fi
echo $fact
}
# Validate input
if ! [[ "$month" =~ ^[1-9]$ ]] && ! [[ "$month" =~ ^1[0-
2]$ ]]; then echo "Invalid input. Please enter a
number between 1 and 12." exit 1
fi
# Get the
current year
year=$(date +
%Y)