0% found this document useful (0 votes)
25 views

OSlab Ishi

Uploaded by

duttaishika3004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

OSlab Ishi

Uploaded by

duttaishika3004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Practical 1

Connect to Linux Server and understand the Basic Directory


Structure of Linux.
Linux is a Unix-like operating system known for its stability, security,
and versatility. It was createdby Linus Torvalds in 1991 and has since
gained widespread popularity in both server and desktopenvironments.
Linux supports a wide range of hardware and has a vibrant community
of developers and users who contribute to its ongoing development and
customization. Its open- source nature allows anyone to modify and
distribute it freely.
History of Linux
The history of Linux is a fascinating journey that began in 1991 when
Linus Torvalds, a Finnish computer science student, started working on
a personal project. Here's a brief overview of its evolution:
1. Inception (1991):
Linus Torvalds announced the creation of a new operating system
kernel on August 25, 1991, in a Usenet post. He wanted to
develop a Unix-like system that could run on his Intel80386-based
personal computer. This kernel eventually became known as
Linux.

2. Open-Source Community (Early 1990s):


Linus released the Linux kernel under the GNU General Public
License (GPL), making itopen source. This decision encouraged
developers worldwide to contribute to its development, resulting in
rapid growth.

3. Growth of the Kernel (Early to Mid-1990s):


The Linux kernel quickly gained support and improvements from a
growing community ofdevelopers. It was compatible with various
hardware and began to feature essentialcomponents of a
complete operating system.

4. Distribution Development (Mid-1990s):


Various Linux distributions, such as Slackware and Red Hat,
emerged, bundling the Linuxkernel with software packages and
creating complete operating systems for users. This made Linux
more accessible to a wider audience.
5. Enterprise Adoption (Late 1990s - Early 2000s):
Linux started gaining popularity in enterprise environments due to
its stability and cost- effectiveness, particularly in server
applications. Companies like IBM and Oracle began offering
support for Linux.

6. User-Friendly Desktop Environments (Early 2000s):


Projects like GNOME and KDE made Linux desktop environments
more user- friendly, attracting a broader audience to Linux as a
desktop operating system.

7. Linux in the Cloud (2010s):


Linux played a significant role in the rise of cloud computing, with
many cloud providersusing Linux-based servers to deliver their
services.

8. Continued Growth (Present):


Linux remains a dominant force in the server and cloud computing
domains. It also playsa crucial role in embedded systems,
supercomputing, and IoT devices.

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:

1. Open Source: Linux is distributed under open-source licenses


(e.g., GNU GPL), which means its source code is freely available
for anyone to view, modify, and distribute. This encourages
collaboration and innovation.
2. Multiuser Support: Linux supports multiple users with individual
accounts, ensuring secure separation of user data and processes.
It's commonly used in multi-user environmentslike servers.
3. Multitasking: Linux allows multiple processes to run
simultaneously, making it a true multitasking operating system. It
efficiently manages CPU resources and scheduling.
4. Stability: Linux is renowned for its stability and reliability. It can
run for extended periods without needing to be rebooted, making it
ideal for servers and critical systems.
5. Security: Linux has robust security features, including user and
group permissions, firewalls, and mandatory access controls (e.g.,
SELinux). Frequent security updates are available to patch
vulnerabilities.

Advantage of Linux

1. Cost- Effective: Linux is free to use, distribute, and modify. This


makes it an attractive option forbusinesses and individuals looking
to save on operating system costs.
2. Open Source: The open-source nature of Linux means that its
source code is accessible and canbe modified by anyone. This
fosters a community of developers who contribute to its
improvement and security.
3. Stability and Reliability: Linux is known for its stability and
reliability. It can run for extendedperiods without needing a reboot,
making it suitable for critical applications and servers.
4. Security: Linux is inherently more secure than some other
operating systems because of its open-source nature. Security
vulnerabilities can be quickly identified and patched by the
community. Additionally, its user-based permission system
enhances security by limiting access to system resources.
5. Customizability: Linux offers a high degree of customizability.
Users and administrators can choose from a wide range of desktop
environments, software, and configurations to tailor their system to
their specific needs.

6. Performance: Linux typically performs well even on older


hardware. It's resource- efficient, which means it can run smoothly
on machines with limited resources.
Disadvantages of Linux

1. Software Compatibility: Linux can face challenges with


software compatibility, especially when it comes to proprietary
software that is primarily designed for Windows ormacOS. While
many alternatives and open-source software options exist, specific
commercial applications may not be available for Linux, which can
be a drawback for userswho rely on such software.
2. Learning Curve: Linux can have a steeper learning curve for
users who are accustomedto other operating systems like
Windows or macOS. The command-line interface (CLI) is
apowerful tool in Linux but may be intimidating for beginners.
However, there are user- friendly distributions with graphical
interfaces to help mitigate this issue.
3. Hardware Support: While Linux supports a wide range of
hardware, certain niche or bleeding edge hardware components may
not have Linux drivers available immediately. This can lead to
compatibility issues for users with specialized hardware needs.
4. Gaming Support: Although Linux gaming has improved
significantly over the years with platforms like Steam offering Linux
support, it still lags behind Windows in terms of gaming
compatibility. Some popular games and game development tools
are primarily designed for Windows, which can be a limitation for
gamers.
5. Limited Support for Some Professional Software: Professionals in
specific fields, such as videoediting, graphic design, or 3D modeling,
may find that some industry- standard software packages (e.g., Adobe
Creative Suite) are not available natively on Linux. While there are
alternatives and workarounds, these may not offer the same level of
functionality or compatibility.

File structure of Linux

The Linux file structure is organized into a hierarchical tree-like system


known as the Filesystem Hierarchy Standard (FHS). At the root of this
structure is the forward slash (/), representing the highest level of the
file system. Essential directories include /bin for system binaries, /etc for
configuration files, and /home for user home directories. /lib and /lib64
store shared libraries, while /usr contains user data and program files.
Dynamic data, like logs and spool files, can be found in /var, and
temporary files are stored in /tmp. Device files are located in /dev,
and /proc provides information about running processes and system
configuration. Directories like /mnt and /media are used for temporarily
mounting external devices.
Practical 2
Write a Program to Understand help commands like: man, info,
help, whatis, apropos.
man command
Displays the manual pages for commands, providing detailed
documentation and usage instructions.
info
Offers a more comprehensive set of documentation compared to man,
often including tutorials and examples.

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

# Check if the character is


uppercase if [[ $char =~ [A-
Z] ]]; then
echo "$char is an
uppercase letter." # Check if
the character is lowercase
elif [[ $char =~ [a-z] ]]; then
echo "$char is a
lowercase letter." # Check if
the character is a digit elif [[
$char =~ [0-9] ]]; then
echo "$char is a
digit." else
echo "$char is not an uppercase letter, lowercase letter, or digit."
fi
Practical 13
Write a basic shell script to display a factorial of a number.
factorial(
){
num=$
1
fact=1

for (( i=1; i<=num;


i++ )) do
fact=$((fact *
i)) done

echo $fact
}

read -p "Enter a positive integer: " number

if ! [[ "$number" =~ ^[0-9]+$ ]] || [ "$number" -


lt 0 ]; then echo "Invalid input. Please enter
a positive integer." exit 1
fi

# Calculate and display the


factorial result=$(factorial
$number)
echo "The factorial of $number is $result."
Practical 14
Write a shell script to input the month number and generate
corresponding calender.
read -p "Enter the month number (1-12): " month

# 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)

# Generate the calendar for the specified month and


current year echo "Calendar for month $month of
year $year:"
cal $month $year
PRACTICAL 15
Write a basic shell script to list all
Directories.
echo "Listing all directories in the current
directory:"

# Use a for loop to iterate through items and display


only directories for item in *; do
if [ -d "$item" ];
then echo
"$item"
fi
don
e

You might also like