Linux
Linux
Why use Linux : Because it is free, open-source, and extremely flexible, Linux is Servers and Hosting: Powers web servers, cloud infrastructure, and database
widely utilized. For servers and developers, it is the ideal option because it offers management systems.
strong security, stability, and performance. Generally interoperable hardware, a
broad software library, and a vibrant community that offers support and regular Development: Used by developers for coding, debugging, and running
updates are the many benefits of Linux. Due to its adaptability, users can applications.
customize the operating system according to their own needs, whether they
become for personal or large enterprise use. Desktop and Personal Use: Provides secure and customizable desktop
environments.
Architecture of Linux : Linux architecture has the following components:
Cybersecurity: Essential for ethical hacking, penetration testing, and security
research.
Embedded Systems: Runs lightweight devices like routers, IoT gadgets, and smart
appliances.
Advantages of Linux : Linux is freely available to use on the internet.It has large
community support.It provides high stability. It rarely slows down or freezes and
there is no need to reboot it after a short time.It maintains the privacy of the
user.The performance of the Linux system is much higher than other operating
systems. It allows a large number of people to work at the same time and it
handles them efficiently.It is network friendly.
Kernel: Kernel is the core of the Linux based operating system. It virtualizes the
Disadvantages of Linux : It is not very user-friendly. So, it may be confusing for
common hardware resources of the computer to provide each process with its
beginners.It has small peripheral hardware drivers as compared to windows.
virtual resources. This makes the process seem as if it is the sole process running
on the machine. The kernel is also responsible for preventing and mitigating
conflicts between different processes. Different types of the kernel are: Linux Features :-
Monolithic Kernel,Hybrid kernels,Exo kernels,Micro kernels.
Multiuser capability: Multiple users can access the same system resources like
memory, hard disk, etc. But they have to use different terminals to operate.
Multitasking: More than one function can be performed simultaneously by It was written by David Korn at AT&T Bell Labs. It is a superset of the Bourne
dividing the CPU time intelligently. shell. So it supports everything in the Bourne shell.It has interactive features. It
includes features like built-in arithmetic and C-like arrays, functions, and string-
Portability: Portability doesn't mean it is smaller in file size or can be carried in manipulation facilities. It is faster than C shell. It is compatible with script written
pen drives or memory cards. It means that it support different types of hardware. for C shell. For the Korn shell the:
Security: It provides security in three ways namely authenticating (by assigning Command full-path name is /bin/ksh,
password and login ID), authorization (by assigning permission to read, write and
execute) and encryption (converts file into an unreadable format). Non-root user default prompt is $,
Live CD/USB: Almost all Linux distros provide live CD/USB so that users can Root user default prompt is #.
run/try it without installing it.
GNU Bourne-Again Shell – Denoted as bash
Graphical User Interface (X Window system): Linux is command line based OS
but it can be converted to GUI based by installing packages. It is compatible to the Bourne shell. It includes features from Korn and Bourne
shell. For the GNU Bourne-Again shell the:
Support's customized keyboard: As it is used worldwide, hence supports
different languages keyboards. Command full-path name is /bin/bash,
Application support: It has its own software repository from where users can Default prompt for a non-root user is bash-g.gg$
download and install many applications.
(g.ggindicates the shell version number like bash-3.50$),
File System: Provides hierarchical file system in which files and directories are
arranged. Root user default prompt is bash-g.gg#.
Open Source: Linux code is freely available to all and is a community based T Shell – Denoted as tsh
development project.
It was originally developed for the Plan 9 operating system, but has since been
Different Shells in Linux :" ported to other systems, including Linux, FreeBSD, and macOS.
SHELL is a program which provides the interface between the user and an Command full-path name is /bin/tcsh,
operating system. When the user logs in OS starts a shell for user.
Default prompt for a non-root user is abhishekaslk(user):~>
Kernel controls all essential computer operations, and provides the restriction to
hardware access, coordinates all executing utilities, and manages Resources Root user default prompt is root@abhishekaslk(user):~#.
between process. Using kernel only user can access utilities provided by
operating system.
Z Shell – Denoted by zsh
Bill Joy created it at the University of California at Berkeley. It incorporated Command full-path name is /bin/zsh,
features such as aliases and command history. It includes helpful programming
features like built-in arithmetic and C-like expression syntax. In C shell:
Default prompt for a non-root user is abhishekaslk(user)%
The Bourne Shell – Denoted as sh 1. Process Management : Creates, schedules, and terminates processes.Handles
process communication and synchronization.Allocates CPU time to processes
It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It is using scheduling algorithms.
faster and more preferred. It lacks features for interactive use like the ability to
recall previous commands. It also lacks built-in arithmetic and logical expression 2. Memory Management : Allocates and deallocates memory for
handling. It is default shell for Solaris OS. For the Bourne shell the: processes.Manages virtual memory using paging and swapping.Ensures efficient
memory utilization and prevents memory leaks.
Command full-path name is /bin/sh and /sbin/sh,
3. File System Management : Controls access to files and directories.Manages file
Non-root user default prompt is $, permissions and ownership.Supports multiple file systems (ext4, NTFS, FAT, etc.).
Root user default prompt is #. 4. Device Management : Interfaces with hardware devices (keyboards, printers,
disks, etc.).Uses device drivers to enable communication between hardware and
The Korn Shell - It is denoted as ksh software.Provides a standardized API for device access.
5. Inter-Process Communication (IPC) : Facilitates communication between 4. Window Managers : Unlike Windows/MacOS, X does not define how windows
processes using pipes, shared memory, message queues, etc.Ensures data should look. Instead, window managers (like GNOME, KDE, XFCE) handle the
integrity and synchronization among processes. appearance and functionality.
6. Networking : Manages network communication using protocols like 5. Protocol and Display Numbering : X uses the DISPLAY environment variable
TCP/IP.Handles data transmission, routing, and security. (:0, :1, etc.) to manage multiple screens.
7. Security & Access Control : Implements user authentication and Common X Window Components :
authorization.Uses permissions and encryption to protect data.Enforces security
policies to prevent unauthorized access. X Server: Core component that controls input/output devices. Examples: Xorg,
XFree86.
8. System Calls & User Interface : Provides system calls (e.g., fork(), exec(),
read(), write()) for applications to interact with the OS.Acts as an interface X Clients: Applications that request display services (e.g., Firefox, LibreOffice).
between user applications and hardware resources.The Linux kernel ensures
smooth interaction between software and hardware, making the operating Window Manager: Controls window placement, appearance, and interactions
system efficient, secure, and scalable. (e.g., GNOME Shell, KDE Plasma).
Linux: Linux could be a free and open supply OS supported operating system X Protocol: Defines communication between X clients and the X server.
standards. It provides programming interface still as programme compatible with
operating system primarily based systems and provides giant selection How X Windows Works in Linux : 1. The X server starts and initializes the display.
applications. A UNIX operating system additionally contains several severally
developed parts, leading to UNIX operating system that is totally compatible and
2. Users launch X clients (applications).
free from proprietary code.
Direct Rendering: Some apps bypass X for better graphics performance (e.g.,
gaming applications).
Key Features of X Windows System : 4. KDE Applications : KDE Plasma comes with a suite of applications,
including:Dolphin – File Manager (feature-rich with tabs, split view, and
1. Client-Server Architecture : The X server manages input/output devices previews).Konsole – Terminal Emulator.Kate & KWrite – Text Editors.Kdenlive –
(display, keyboard, mouse).X clients (applications like browsers, editors) Video Editor.Okular – Document and PDF Viewer.
communicate with the X server.
5. KDE Connect (Device Integration) : Connect your Android phone to your PC for
2. Network Transparency : X allows running applications on a remote machine file sharing, SMS notifications, clipboard syncing, and remote control.
while displaying them on a local machine.
6. Multiple Workspaces & Activities : Supports virtual desktops for better
3. Modular and Extensible : The system can be customized with different multitasking.Activities help organize different workflows separately.
window managers and desktop environments.
7. Wayland & X11 Support : Supports X11 (legacy display server) and Wayland
(modern, secure alternative).
1. Minimalistic & Modern UI : Uses a single-panel layout with a top bar, Activities
Overview, and a dock.No desktop icons by default (but can be enabled with
extensions).
1. Root Directory (/) : The top-most directory in Linux.All other directories and
4. Extensions & Customization : GNOME is less customizable than KDE but allows
files are placed under /.It contains essential system directories like /bin, /etc,
tweaks using : GNOME Tweaks – Adjust themes, fonts, and icons.GNOME
/var, etc.
Extensions – Add extra functionality like a system tray or desktop icons.dconf
Editor – Advanced configuration tool.
2. Essential System Directories :
/lib (Libraries) : Holds essential shared libraries needed by binaries in /bin and
XFCE4 (XForms Common Environment 4) : XFCE4 is a lightweight, fast, and highly
/sbin.
efficient desktop environment for Linux and Unix-like operating systems. It is
designed to be resource-friendly while still providing a traditional and user-
friendly interface. XFCE is a great choice for older hardware or users who prefer Examples: libc.so, ld-linux.so.
speed over visual effects.
/lib64 (64-bit Libraries) : Contains 64-bit versions of shared libraries for 64-bit
Key Features of XFCE4 : systems.
1. Lightweight & Fast Performance : Uses low system resources, making it ideal 3. User and Application Directories : /home (User Home Directories)
for older or low-power computers.Faster than GNOME and KDE due to minimal
background services. Contains personal directories for each user.
2. Traditional Desktop Layout : Windows-like interface with a panel, menu, Example: /home/user1, /home/user2.
system tray, and icons.Supports multiple panels and customizable widgets.
/root (Root User’s Home Directory) : Home directory for the root
3. Highly Customizable : Change themes, icons, and fonts using the XFCE Settings (superuser).Separate from /home to maintain security.
Manager. Supports third-party themes and extensions.Customizable panel layout
and menu structure. /usr (User Binaries & Applications) : Stores user-related programs, libraries, and
documentation.
4. Core XFCE Applications : XFCE includes a set of lightweight applications, such
as : Thunar – File Manager (fast and minimal).XFCE Terminal – Terminal Subdirectories : /usr/bin: Non-essential user binaries (e.g., vim, gcc).
Emulator.Mousepad – Text Editor. Ristretto – Image Viewer.Parole – Media
Player. /usr/sbin: Non-essential system binaries (e.g., apache2, sshd).
5. Window & Workspace Management : Supports virtual desktops for better /usr/lib: Libraries for /usr/bin and /usr/sbin.
multitasking.Uses xfwm4 (XFCE’s window manager) for snappy performance.
/usr/local: Locally installed programs (outside package manager control).
6. Low Resource Usage : Uses very little RAM and CPU, making it perfect for
systems with limited hardware.Consumes less power, making it ideal for laptops. 4. System Runtime and Temporary Data :
/var (Variable Data) The Linux file system is a structured way to store and manage data on storage
devices like hard disks, SSDs, and USB drives. It consists of several key parts that
Stores logs, caches, spool files, and other dynamic data. work together to ensure data is efficiently stored, accessed, and managed. Below
is a detailed breakdown of the different parts of a Linux file system.
Subdirectories : /var/log: Log files (e.g., /var/log/syslog).
1. Boot Block (MBR/GPT) : The boot block is the first sector of a storage device.It
/var/tmp: Temporary files that persist after a reboot. contains the Master Boot Record (MBR) or GUID Partition Table (GPT), which
stores information about partitions and the bootloader.MBR: Used in older
/tmp (Temporary Files) systems, supports up to 2TB disks.GPT: Used in modern systems, supports larger
disks and more partitions.
Stores temporary files created by applications.Files here are usually deleted on
system reboot. 2. Superblock : The superblock contains critical metadata about the file system.It
stores information such as:File system type (e.g., ext4, XFS, Btrfs).Total number of
inodes and blocks. Free and used block counts.Block size.Mount status and state
5. Device and Special Purpose Directories :
of the file system.The superblock is replicated multiple times across the disk to
prevent data loss.
/dev (Device Files) : Contains files representing hardware devices.
3. Inode Table (Index Nodes) : Inodes store metadata about files and
Examples : /dev/sda1: First partition of the first hard drive.
directories.Each file/directory has an inode number, which contains:File type
(regular file, directory, symbolic link, etc.).File permissions and ownership (user,
/dev/null: Discard any data written to it.
group).File size.Time stamps (created, modified, accessed).Pointers to data blocks
storing the actual file content.The inode does not store the file name—file names
/proc (Process Information) are stored in directory entries.
A virtual filesystem providing information about system processes. 4. Data Blocks : The actual content of files is stored in data blocks.The inode table
keeps track of which blocks belong to which files.If a file is large, it spans multiple
Example : /proc/cpuinfo: CPU details. blocks, and the inode holds pointers to these blocks.
/proc/meminfo: Memory usage. 5. Journal (for Journaling File Systems) : A journal is used in journaling file
systems (ext3, ext4, XFS, Btrfs) to prevent data corruption.Before writing changes
/sys (System Information) to the main file system, they are logged in the journal.If the system crashes
during a write operation, the journal can help recover lost data.
Exposes kernel and hardware-related system information.
6. Directory Structure : Directories in Linux are special files that store references
Works closely with /proc. (links) to files and other directories.A directory entry contains:File
name.Corresponding inode number.The ls -i command can display the inode
/mnt (Mount Directory) number of files.
Temporary mount point for manually mounted filesystems. 7. Special File Types : Apart from regular files and directories, Linux supports :
Symbolic Links (Soft Links): Point to another file or directory.
/media (Removable Media)
Hard Links: Create another name for an existing file, sharing the same inode.
Automatically mounted removable devices like USB drives and CDs.
Device Files (/dev): Represent hardware devices as files.
6. Boot and Kernel Files :
Pipes & Sockets: Used for inter-process communication.
/boot (Boot Files)
Here are the commands to add a user, add a group, and delete a group in Linux
Contains files required for booting the system. for the given user and group names:
Examples : vmlinuz: Compressed Linux kernel. 1. Add a New User (testuse) : sudo useradd testuse
initrd: Initial RAM disk image. This creates a new user testuse without a home directory.
7. Special Purpose Directories : /run (Runtime Data) 2. Add a New Group (testgroup) : sudo groupadd testgroup
Holds system runtime data like process IDs (/run/sshd.pid). This creates a new group named testgroup.
Replaces /var/run in newer Linux versions. 3. Add User testuse to Group testgroup : sudo usermod -aG testgroup testuse
/srv (Service Data) This adds testuse to the testgroup without removing them from other groups.
Stores data for system services like web and FTP servers. 4. Verify Group Membership : groups testuse
This will list all groups the user testuse belongs to.
5. Delete the Group (testgroup) : sudo groupdel testgroup Applies ownership change to all files inside the directory.
This removes the group testgroup (make sure no active processes are using it). chgrp (Change Group Ownership) : Used to change the group associated with a
file.
File Permissions in Linux : Linux uses a permission system to control access to
files and directories. Each file and directory has three types of permissions 1. Change Group Ownership : chgrp newgroup file.txt
assigned to three categories of users.
Assigns newgroup as the group for file.txt.
1. Types of Users : Owner (u): The user who created the file.Group (g): A group
of users who can access the file. Others (o): All other users. 2. Change Group Ownership Recursively : chgrp -R newgroup /path/to/directory
chmod (Change File Permissions) : Used to change file permissions using Changes group ownership for all files inside the directory.
symbolic (rwx) or numeric (0-7) notation.
File and Directory Management Commands in Linux : Linux provides various
1. Using Numeric Mode : Each permission is represented by a number: commands to manage files and directories. Here are some commonly used
commands with short examples:
7 → Read (4) + Write (2) + Execute (1) = rwx
1. mkdir (Make Directory) : Used to create new directories.
6 → Read (4) + Write (2) = rw-
Example: Create a Directory
5 → Read (4) + Execute (1) = r-x
mkdir myfolder
4 → Read only = r--
Creates a directory named myfolder.
0 → No permission = ---
Example: Create Multiple Directories
Example: Grant full permission to the owner, read & execute for group, and read-
only for others mkdir folder1 folder2 folder3
2. Using Symbolic Mode : + → Add permission. 2. rmdir (Remove Directory) : Used to delete empty directories.
Example: Add execute permission to the owner Example: Remove Multiple Empty Directories
Example: Remove write permission from group Deletes folder1 and folder2 if they are empty.
Example: Set permissions exactly to read & write for everyone 3. cd (Change Directory) : Used to navigate between directories.
chown (Change File Ownership) : Used to change the owner and/or group of a cd myfolder
file.
Changes into myfolder.
1. Change the Owner : chown newuser file.txt
Example: Move to Parent Directory
Assigns ownership of file.txt to newuser.
cd ..
2. Change Owner and Group : chown newuser:newgroup file.txt
Moves up one level.
Changes the owner to newuser and group to newgroup.
Example: Move to Home Directory
3. Change Ownership Recursively (for all files in a directory) : chown -R
newuser:newgroup /path/to/directory cd ~
Takes you to the home directory. 2. Show the Last 5 Lines : tail -n 5 file.txt
Example: Move to the Root Directory 3. Show the Last 20 Bytes : tail -c 20 file.txt
Takes you to the root (/) directory. Useful for monitoring real-time logs.
4. pwd (Print Working Directory) : Displays the current directory's full path. 3. cut (Extract Specific Columns or Characters) : The cut command extracts
portions of text from each line of a file.
Example: Show Current Directory
Syntax : cut [options] filename
pwd
Examples : 1. Extract the First 10 Characters : cut -c 1-10 file.txt
Output : /home/user/myfolder
2. Extract the 2nd and 4th Columns (Using Delimiter :) : cut -d':' -f2,4 file.txt
5. ls (List Files and Directories) : Used to display files and directories.
3. Extract the First Column (Default Delimiter: Tab) : cut -f1 file.txt
Example: List Files in Current Directory
4. paste (Merge Lines or Columns) : The paste command merges lines or columns
ls from multiple files.
Example: List Files with Details Syntax : paste [options] file1 file2
Displays detailed information like permissions, owner, size, and modification Each line from file1.txt and file2.txt is joined with a Tab.
date.
2. Merge Using a Comma Instead of a Tab : paste -d ',' file1.txt file2.txt
Example: Show Hidden Files
3. Merge Each Line Into a Single Line : paste -s file.txt
ls -a
Converts a multi-line file into a single-line output.
Lists all files, including hidden files (starting with .).
5. sort (Sort Lines in a File) : The sort command arranges lines in alphabetical or
Example: List Files with Human-Readable Sizes numerical order.
Displays sizes in KB, MB, or GB. Examples : 1. Sort Alphabetically : sort names.txt
Example: Sort Files by Modification Time 2. Sort in Reverse Order : sort -r names.txt
Sorts files by latest modification time. 4. Sort by Second Column (Using : as Delimiter) : sort -t':' -k2 file.txt
Filter Commands in Linux : Filter commands in Linux process text data by -t':' → Specifies : as the delimiter
modifying or extracting specific parts of a file. These commands are mostly used
with pipes (|) to filter large data efficiently. -k2 → Sorts based on the 2nd column
1. head (Display First N Lines of a File) : The head command is used to display the 6. uniq (Remove Duplicate Lines) : The uniq command removes consecutive
first 10 lines of a file by default. duplicate lines.
Examples : 1. Show the First 10 Lines (Default) : head file.txt Examples : 1. Remove Duplicate Lines : uniq file.txt
2. Show the First 5 Lines : head -n 5 file.txt Only removes consecutive duplicates.
3. Show First 20 Bytes : head -c 20 file.txt 2. Count Duplicate Lines : uniq -c file.txt
2. tail (Display Last N Lines of a File) : The tail command shows the last 10 lines Prefixes each line with count of occurrences.
of a file by default.
3. Show Only Duplicate Lines : uniq -d file.txt
Syntax : tail [options] filename
4. Show Only Unique Lines : uniq -u file.txt
Examples : 1. Show the Last 10 Lines (Default) : tail file.txt
7. grep (Search for a Pattern in a File) : The grep command searches for specific
words, phrases, or patterns.
Text Editors in Linux: vi and vim : Linux provides powerful text editors like vi and
vim for editing configuration files, writing scripts, and developing code.
3. Ex Mode (Last Line Mode) → For saving, quitting, and executing commands.
n → Blocks messages.
talk user1
talk [email protected]
talk username
If the user is logged in multiple times, specify their TTY. pkill -u user1 → Kills all processes owned by user1.
Example : Send a message to user1: 5. nice (Set Process Priority) : The nice command starts a new process with a
specific priority. The priority range is from -20 (highest priority) to 19 (lowest
write user1 priority), with the default being 0.
Start typing the message and press Ctrl + D to end the message. nice -n 10 python script.py → Runs python script.py with a lower priority.
4. wall (Broadcast Message to All Users) : The wall command sends a message to sudo nice -n -5 ./heavy_task → Runs a process with a higher priority (negative
all logged-in users. values require sudo).
Only root users can send messages when users have mesg n enabled.
5. mail (Send Emails from Terminal) : The mail command is used to send emails
from the terminal.
Example : Send an email : echo "Hello, this is a test email." | mail -s "Test Email"
[email protected]
ps -u username → Lists processes owned by a specific user. RAID Levels and Their Features :
2. top (Real-Time Process Monitoring) : The top command provides a real-time 1. RAID 0 (Striping, No Redundancy) : Data is split across multiple disks to
view of system processes, displaying information like CPU and memory improve speed.No redundancy – If one disk fails, all data is lost.Minimum Disks
usage.Running top opens an interactive interface where processes are updated Required: 2
dynamically.Press k to kill a process, r to renice (change priority), Shift + P to sort
by CPU usage, and Shift + M to sort by memory usage.Press q to exit top.
Use Case: High-speed applications like video editing.
kill PID → Sends the default SIGTERM signal to terminate a process gracefully.
2. RAID 1 (Mirroring, High Redundancy) : Data is duplicated (mirrored) on two
disks.Provides fault tolerance – If one disk fails, data remains safe on the
kill -9 PID → Forcefully kills a process using SIGKILL. other.Minimum Disks Required: 2
kill -1 PID → Restarts a process using SIGHUP. Use Case: Critical systems where data loss is unacceptable.
4. pkill (Kill Process by Name) : Instead of using PIDs, the pkill command allows Example Setup : mdadm --create --verbose /dev/md0 --level=1 --raid-
killing processes by their name. devices=2 /dev/sdb /dev/sdc
3. RAID 5 (Striping with Parity, Balanced Performance & Redundancy) : Data is pvdisplay
striped across disks with parity information stored on different disks.Provides
fault tolerance – Can survive one disk failure.Minimum Disks Required: 3 Step 2: Create a Volume Group (VG)
Use Case: Balanced performance and redundancy for databases & servers. Create a volume group named vg_data:
Example Setup : mdadm --create --verbose /dev/md0 --level=5 --raid- vgcreate vg_data /dev/sdb /dev/sdc
devices=3 /dev/sdb /dev/sdc /dev/sdd
Check VGs:
4. RAID 6 (Striping with Double Parity, Extra Fault Tolerance) : Similar to RAID 5
but stores two sets of parity data for extra security.Can survive two disk vgdisplay
failures.Minimum Disks Required: 4
Step 3: Create Logical Volumes (LV)
Use Case: Enterprise environments needing high fault tolerance.
Create a 50GB logical volume named lv_home:
Example Setup : mdadm --create --verbose /dev/md0 --level=6 --raid-
devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde lvcreate -L 50G -n lv_home vg_data
5. RAID 10 (RAID 1 + RAID 0, Best of Both Worlds) : Combines RAID 1 (mirroring) Or create an LV using all free space:
and RAID 0 (striping).Provides speed and redundancy but requires more
disks.Minimum Disks Required: 4
lvcreate -l 100%FREE -n lv_storage vg_data
mkfs.ext4 /dev/vg_data/lv_home
Advantages of LVM :Dynamic Partitioning: Resize partitions (logical volumes)
without rebooting. Better Storage Utilization: Combine multiple physical disks
Create a mount point and mount the LV:
into a single logical volume.
mkdir /mnt/home
Snapshots: Take instant backups of volumes.
4. Physical Extents (PE) : LVM divides disks into PEs (Physical Extents), which are mount /dev/vg_data/lv_home /mnt/home
small fixed-size chunks (default: 4MB).
Step 6: Take LVM Snapshots (Backup Purpose)
How to Use LVM in Linux :
Create a snapshot of lv_home:
Step 1: Create Physical Volumes (PV)
lvcreate -L 5G -s -n lv_home_snapshot /dev/vg_data/lv_home
Convert raw disks or partitions into LVM physical volumes:
Remove snapshot:
pvcreate /dev/sdb /dev/sdc
lvremove /dev/vg_data/lv_home_snapshot
Check PVs:
Who is a System Administrator : A System Administrator (SysAdmin) is
responsible for managing and maintaining a company’s IT infrastructure, servers,
networks, and security systems to ensure smooth and efficient operations. They 3. Kernel initializes hardware and starts system processes.
handle installation, configuration, troubleshooting, security, and performance
monitoring of hardware and software. 4. The OS boots into the user environment.
1. Server and System Management : Install, configure, and maintain operating sudo update-grub
systems (Linux, Windows, etc.).Manage server hardware, storage, and virtual
machines (VMs).Perform software updates, patches, and security fixes.Monitor Reinstall GRUB bootloader (for MBR-based systems):
CPU, memory, and disk usage to prevent performance issues.
sudo grub-install /dev/sda
2. User and Access Management : Create, manage, and delete user accounts and
permissions. Set up role-based access control (RBAC) for security.Manage 2. LILO (Linux Loader) – Legacy Boot Loader : LILO is an older boot loader that
authentication systems like Active Directory (AD), LDAP, SSH keys. was widely used before GRUB. It is simpler but lacks advanced features.
3. Network Administration : Configure and maintain routers, switches, and Features of LILO : Simple and lightweight bootloader.Supports multiple OS
firewalls.Monitor network traffic and bandwidth usage.Set up and manage VPNs, booting, but requires manual reconfiguration.Does not have a menu interface like
DNS, DHCP, and IP addressing. Troubleshoot connectivity issues and optimize GRUB.Limited support for modern file systems.Cannot dynamically detect new
network performance. kernels (must be manually updated).No network boot support.
4. Security Management : Implement firewalls, intrusion detection systems (IDS), LILO Boot Process : 1. BIOS loads LILO from the MBR.
and encryption.Regularly update antivirus and malware protection.Conduct
security audits, log monitoring, and vulnerability assessments.Enforce password
2. LILO loads the Linux kernel.
policies, multi-factor authentication (MFA), and access controls.
8. Log Management and Monitoring : Use tools like Nagios, Zabbix, Prometheus,
or Grafana to monitor servers.Analyze system logs using journalctl, syslog, and
ELK Stack (Elasticsearch, Logstash, Kibana).Troubleshoot issues based on log
reports and alerts.
A boot loader is a program that loads the operating system (OS) into memory
when a computer starts. It is the first software that runs after the BIOS/UEFI
initializes the hardware.
1. GRUB (Grand Unified Bootloader) : GRUB is the most widely used bootloader
in modern Linux systems. It is highly flexible, powerful, and supports multiple Wo
OSes. rking of Various Servers in Linux : Each server in Linux performs a specific role in
networking, file sharing, web hosting, and remote access. Below is a detailed
Features of GRUB : Supports multiple operating systems (Linux, Windows, explanation of how each server works, along with its key components.
etc.).Supports different file systems (ext4, XFS, FAT32, NTFS, etc.).Allows boot-
time kernel parameter modifications.Provides a menu-driven interface for 1. DHCP Server (Dynamic Host Configuration Protocol) : A DHCP server
booting.Supports password protection for security.Can boot from network (PXE automatically assigns IP addresses and network configurations to clients.
booting).Supports Logical Volume Manager (LVM) and RAID.
Working : 1. Client Broadcasts a DHCP Discovery Request → The device (PC,
GRUB Boot Process : 1. BIOS/UEFI loads GRUB into memory. mobile, etc.) sends a request to find a DHCP server.
2. GRUB loads the kernel and initramfs. 2. DHCP Server Responds with an Offer → The server offers an available IP
address and network settings.
3. Client Requests the Offered IP → The client accepts the offer by sending a Working : 1. User Connects Using Telnet → telnet 192.168.1.10
DHCP Request.
2. Server Authenticates the User → The user enters a username and password.
4. DHCP Server Assigns the IP → The server confirms the assignment and updates
its database. 3. User Gains Shell Access → The client gets a remote command-line interface.
Real-Life Example : When you connect your phone to Wi-Fi, the router's DHCP 4. User Executes Commands → The user can manage files, install software, etc.
server assigns an IP address dynamically.
Real-Life Example : An admin logs into a Linux server remotely using Telnet (not
2. DNS Server (Domain Name System) : A DNS server converts human-readable secure, replaced by SSH).
domain names (e.g., google.com) into IP addresses.
6. FTP Server (File Transfer Protocol) : FTP is used to transfer files between a
Working : 1. User Enters a Domain Name → A user types www.example.com in a client and a server.
browser.
Working : 1. User Connects to FTP Server → ftp 192.168.1.10
2. DNS Resolver Contacts Root Server → The local DNS resolver checks its cache.
If the domain isn’t found, it queries the root DNS server. 2. User Authenticates with Username and Password.
3. Root Server Directs to TLD Server → The root server sends the request to the 3. User Browses Files → List directories using : ls
Top-Level Domain (TLD) server (e.g., .com).
4. File Transfer Happens → Download a file:
4. TLD Server Directs to the Authoritative DNS Server → The TLD server sends the
request to example.com’s authoritative DNS server. get file.txt
5. IP Address is Returned → The authoritative DNS server responds with the IP Upload a file:
(192.168.1.20).
put file.txt
6. Browser Connects to the Website → The browser loads the website using the
IP address.
5. User Disconnects → bye
Real-Life Example : When you visit www.youtube.com, your ISP’s DNS server
Real-Life Example : Web developers upload website files to a hosting server using
resolves it to 142.250.183.206.
FTP clients like FileZilla.
3. If Not Cached, Squid Fetches Data → Squid requests the page from the original
3. User Authenticates → The user enters login credentials.
website.
4. User Reads/Writes Files → Files are shared and modified across OS platforms.
4. Squid Caches the Response → The website content is stored for future
requests.
5. Session Closes When Done.
5. User Receives the Response → The client gets the webpage, either from the
Real-Life Example : A Linux file server shares files across Windows machines in an
cache or the web.
office.
Real-Life Example : A company uses Squid to block social media websites while
What is Shell Scripting : A shell script is a program written for the Linux shell to
allowing access to work-related sites.
automate tasks. It contains a series of commands that execute sequentially. Shell
scripts are used for system administration, task automation, and process
4. Apache Web Server : Apache is an open-source web server used for hosting
management.
websites and serving web pages.
Step 4: Make the Script Executable : chmod +x hello.sh echo "Number is greater than 5 but less than or equal to 15"
1. Conditional Statements (if, if-else, case) – Execute commands based on (d) case Statement : Used for multiple choices, similar to switch-case in other
conditions. languages.
2. Looping Statements (for, while, until) – Repeat commands multiple times. Example : #!/bin/bash
3. Jump Statements (break, continue, exit) – Control the flow of execution. echo "Enter a number (1-3):"
num=10 esac
fi 2. Looping Statements :
Output : Number is greater than 5 (a) for Loop : Repeats commands for a fixed number of times.
(b) if-else Statement : Executes different commands for true and false conditions. Example : #!/bin/bash
num=3 do
fi Iteration: 3
Example : #!/bin/bash (b) while Loop : Executes commands while a condition is true.
((count++)) (b) continue Statement : Skips the current iteration and moves to the next one.
Count: 2 do
Count: 4 continue
Count: 5 fi
(c) until Loop : Executes commands until a condition becomes true. echo "Value: $i"
do Value: 4
Number: 2 exit 1
Number: 5 Meta Characters in Linux Shell Scripting : Meta characters are special symbols
that have a unique meaning in the Linux shell. They are used for wildcards,
3. Jump Statements : redirections, piping, quoting, and command execution.
(a) break Statement : Exits a loop when a condition is met. Common Meta Characters and Their Uses :
Example : #!/bin/bash
for i in {1..10}
do
if [ $i -eq 5 ]; then
break
fi
done
Output : Value: 1
Value: 2
[ condition ] && command1 || command2 → Executes command1 if the
condition is true, otherwise executes command2.
10 is Even
#!/bin/bash
read num
is_prime=1
done
[ $num -gt 1 ] && [ $is_prime -eq 1 ] && echo "$num is Prime" || echo "$num is
Not Prime"
rm missingfile || echo "File not found" # Runs second command if rm fails #!/bin/bash
3. Redirection (>, >>, <) : echo "Hello" > output.txt # Overwrites file with "Hello" echo "Enter a number:"
4. Pipes (|) : ls -l | grep ".txt" # Lists only .txt files while [ $temp -gt 0 ]; do
5. Quoting (" ", ' ', ` `) : echo "Today is $(date)" # Expands command digit=$((temp % 10))
6. Background Execution (&) : sleep 10 & # Runs sleep command in the temp=$((temp / 10))
background
done
**Shell script for checking :
[ $sum -eq $num ] && echo "$num is Armstrong" || echo "$num is Not
1. Check Even or Odd : Script: Armstrong"
#!/bin/bash Explanation : An Armstrong number is a number where the sum of its digits
raised to the power of the number of digits equals the number itself.The script
echo "Enter a number:" extracts each digit, raises it to the power of n (total digits), and adds it to sum.If
sum == num, then it’s an Armstrong number.
read num
Example Output : Enter a number : 153
[ $((num % 2)) -eq 0 ] && echo "$num is Even" || echo "$num is Odd"
153 is Armstrong
Explanation : read num → Reads a number from the user.
4. Check Palindrome Number : Script:
$((num % 2)) → Checks if the remainder when divided by 2 is 0.
#!/bin/bash echo "First Argument: $1"
[ "$num" -eq "$(echo "$num" | rev)" ] && echo "$num is Palindrome" || echo echo "Total Number of Arguments: $#"
"$num is Not Palindrome"
Run the script with arguments : bash args.sh Hello World
Explanation : A palindrome number reads the same forward and backward.rev
command reverses the number.If num == reversed(num), then it’s a palindrome. Output : Script Name: args.sh
for ((i = 1; i <= num; i++)); do fact=$((fact * i)); done $# → Number of arguments
echo "Factorial of $num is $fact" 2. Retrieving Return Values from Functions : Shell functions return values using
echo or return. Method 1: Using echo (Recommended) : Functions in shell scripts
Explanation : Factorial of n is n! = n * (n-1) * (n-2) ... * 1.Loop runs from 1 to num, do not return values like other programming languages. Instead, they print the
multiplying each value.The final factorial is printed. value, which can be captured using command substitution $( ).
cat "$file1" "$file2" > merged.txt && echo "Files merged into 'merged.txt'" echo "Sum is: $result"
Explanation : read file1 file2 → Reads two file names.cat "$file1" "$file2" > Output : Sum is: 8
merged.txt → Merges contents into a new file merged.txt.&& echo "Files
merged" → Displays success message if merge is successful. Method 2: Using return (Only for Status Codes) : The return statement only
returns an exit status (0-255).
Example Output : Enter two filenames to merge:
Example : #!/bin/bash
file1.txt file2.txt
check_even() {
Files merged into 'merged.txt'
[ $(( $1 % 2 )) -eq 0 ] && return 0 || return 1
Passing Arguments to a Shell Script & Retrieving Return Values from Functions :
}
1. Passing Arguments to a Shell Script : When running a shell script, you can pass
arguments directly in the command line. check_even 10
Explanation : $? captures the exit status of the last executed command. ls -l | less
Redirection in Linux – Redirection in Linux allows you to change the input and less → Displays output page by page.
output sources for commands. It controls how data flows between the terminal,
files, and programs. This is useful when there are many files and you want to scroll through them.
1.Input Redirection (<) : By default, commands read input from the keyboard
(stdin). The < operator tells the command to read input from a file instead.
2. Output Redirection (> and >>) : By default, commands display output on the
screen (stdout). The > and >> operators redirect this output to a file.
Overwrite Output (>) : The > operator replaces existing file content.
Append Output (>>) : The >> operator adds new output to the file without
deleting the existing content.
Explanation : Appends the current date to log.txt. Keeps previous data intact
3. Error Redirection (2>, 2>>) : By default, error messages (stderr) are displayed
on the screen. We can redirect them to a file instead.Redirect Errors to a File
(2>)The 2> operator saves only error messages into a file.
Append Errors to a File (2>>) : The 2>> operator adds error messages to an
existing file without deleting old errors.
What is Piping : Piping (|) is a method in Linux to send the output of one
command as the input to another command. This helps in chaining multiple
commands together to process data efficiently.
How Does Piping Work : Without pipes: We store output in a file and then use it
as input for another command.With pipes: We directly pass output from one
command to another.