Linux Unit 1
Linux Unit 1
interaction ko manage karta hai. Yeh user aur computer ke hardware ke beech ek interface
provide karta hai. Operating system ki madad se hum computer ke resources jaise ki CPU,
memory, storage, aur input/output devices ko efficiently use kar sakte hain.
Kuch main tasks jo operating system perform karta hai:
1. Resource management: Hardware resources jaise CPU, memory, storage, aur devices
ko manage karna.
2. File management: Files ko store, retrieve, aur organize karna.
3. Task management: Programs aur processes ko execute karna aur unhe manage karna.
4. Security: User ke data ko protect karna aur unauthorized access ko rokna.
5. User interface: User ke liye ek interface provide karna jisme wo computer ke saath
interact kar sake, jaise ki graphical user interface (GUI) ya command line interface
(CLI).
Popular operating systems ke examples hain:
Windows
MacOS
Linux
Android
iOS
In operating systems ka use alag-alag devices mein hota hai, jaise ki personal computers,
smartphones, aur tablets.
Linux ek open-source operating system hai jo Unix-based hai. Yeh ek free aur customizable
OS hai, jisme koi bhi user uske source code ko dekh sakta hai, modify kar sakta hai, aur
distribute kar sakta hai. Linux ka development 1991 mein Linus Torvalds ne start kiya tha.
Linux ka sabse bada feature uski open-source nature hai, jo duniya bhar ke developers ko
isko modify karne aur apne needs ke hisaab se customize karne ka moka deta hai. Iske
alawa, Linux bahut stable, secure, aur fast hota hai, isliye yeh servers, supercomputers, aur
embedded systems ke liye bhi kaafi popular hai.
Linux ke kuch features:
1. Open Source: Linux ka source code free mein available hai, aur koi bhi isse use,
modify, aur distribute kar sakta hai.
2. Security: Linux mein security features bahut strong hote hain, jaise access control aur
user permissions.
3. Multi-tasking: Linux multiple tasks ko ek saath efficiently manage kar sakta hai.
4. Customizable: Users apne requirements ke according Linux ko customize kar sakte
hain.
5. Stable aur Reliable: Linux ka system bahut stable hota hai, isliye yeh critical systems
aur servers mein extensively use hota hai.
Linux ke kuch popular distributions (distros) hain:
Ubuntu
Fedora
Debian
CentOS
Arch Linux
Yeh distributions apne users ke liye different features aur tools offer karte hain. For
example, Ubuntu beginners ke liye kaafi user-friendly hai, jabki Arch Linux advanced users
ke liye zyada customizable hota hai.
Linux ki history kaafi interesting hai aur iski shuruat 1991 mein hui thi. Yaha par main aapko
Linux ke development ke important milestones bata raha hoon:
1. Unix se Prerna (1960s - 1970s)
Linux ka concept Unix operating system se aaya tha. Unix ek multi-tasking aur multi-user OS
tha jo 1970s mein AT&T Bell Labs ke researchers ne develop kiya tha. Unix ka design simple
aur powerful tha, aur isne bohot saare ideas diye jo baad mein Linux mein incorporate kiye
gaye.
2. Linus Torvalds aur Linux ki Shuruat (1991)
Linux ki asli shuruat Linus Torvalds ne 1991 mein ki thi. Linus Torvalds, jo ek Finnish
software developer the, ne apne college project ke roop mein Linux ka pehla version likhna
start kiya. Wo apne computer pe ek free version of Unix ka alternative banana chahte the, jo
freely distribute kiya ja sake.
Linus ne 1991 mein apni development ka announcement ek public newsgroup mein diya
tha, jahan unhone apne project ko "Linux" naam diya, jo unke apne naam "Linus" aur Unix
ka combination tha.
Linus ka pehla version, Linux 0.01, September 1991 mein release hua tha. Yeh sirf x86
architecture wale personal computers ke liye tha aur bohot basic tha. Lekin isne ek
foundation banayi jisme logon ne ispe kaam karna shuru kiya.
3. Open Source Community ka Growth (1990s)
Jab Linus ne Linux ka source code freely distribute kiya, tab Linux ek open-source project
ban gaya. Iska matlab tha ki koi bhi developer iske code ko modify kar sakta tha aur apni
needs ke hisaab se use kar sakta tha.
GNU (GNU's Not Unix) project ke founder, Richard Stallman, jo free software movement ke
liye kaam kar rahe the, unhone Linux ko apni tools aur utilities se integrate kiya. GNU tools
jaise GCC (GNU Compiler Collection), Bash shell, aur Coreutils Linux mein use hone lage,
jisse Linux ek puri operating system ban gaya.
4. Linux Distributions ka Vikas (1990s - 2000s)
1990s ke dauran, kai popular Linux distributions (distros) ban gaye, jo alag-alag needs ko
cater karte the. Red Hat Linux aur Debian jese distros kaafi popular hue. Uske baad, 2000s
mein Ubuntu ka emergence hua, jo beginners ke liye user-friendly aur accessible tha.
5. Linux ka Server aur Enterprise Adoption (2000s - Present)
Linux ko apni stability, security, aur cost-effectiveness ke liye servers aur enterprise
environments mein kaafi use kiya gaya. Web servers (like Apache) aur databases (like
MySQL) ke liye Linux popular platform ban gaya. Major companies jaise Google, Facebook,
Amazon, aur NASA ne apne infrastructure ke liye Linux ko adopt kiya.
6. Mobile aur Embedded Systems mein Growth (2000s - Present)
2000s ke baad, Linux ka adoption mobile aur embedded devices mein bhi bada. Android, jo
ki Linux ka ek customized version hai, duniya ka sabse zyada use hone wala mobile
operating system ban gaya. Iske alawa, Linux ka use embedded systems, smart TVs, routers,
aur even space missions mein bhi hone laga.
7. Current State
Aaj ke din, Linux duniya ke sabse zyada use hone wale operating systems mein se ek hai. Yeh
servers, smartphones, supercomputers, embedded systems, aur cloud environments mein
extensively use hota hai. Open-source nature ke wajah se, Linux ki development ab duniya
bhar ke developers ke dwara ho rahi hai, jo isse har din behtar bana rahe hain.
Conclusion:
Linux ki history ek interesting journey rahi hai jo ek small college project se shuru ho kar ek
global phenomenon ban gayi. Aaj, Linux na sirf personal computers, balki servers, cloud
computing, smartphones, aur embedded devices mein bhi apna prabhav dikhata hai.
LINUX DISTRIBUTIONS :
Yeh sabhi Linux distributions apne unique features aur use cases ke liye jane jate hain. Main
aapko inke bare mein 1-by-1 bataunga, taaki aapko inke differences samajh mein aaye.
1. Red Hat (RHEL)
Type: Enterprise, Server
Base: Independent (but CentOS is based on RHEL)
Key Features: Stability, security, long-term support, enterprise-level support,
subscription-based
Use Case: Large enterprises, data centers, critical production environments
Description: Red Hat Enterprise Linux (RHEL) ek commercial Linux distribution hai, jo
primarily enterprises aur servers ke liye design kiya gaya hai. Yeh high stability,
security, aur long-term support offer karta hai. Red Hat ka subscription-based model
hai jisme 24/7 customer support aur regular patches provided hote hain. Yeh highly
secure aur scalable solution hai jo mission-critical workloads ko handle karta hai.
2. CentOS
Type: Server, Enterprise
Base: Red Hat (RHEL)
Key Features: Free alternative to RHEL, stability, security updates, community-driven
Use Case: Servers, enterprise environments where cost is a concern
Description: CentOS Red Hat Enterprise Linux ka free version hai. Yeh RHEL ke
codebase par based hai, lekin isme commercial support nahi hota. CentOS ko un
enterprises ke liye design kiya gaya hai jo RHEL ki features chahte hain par uski cost
nahi afford kar sakte. CentOS long-term stability aur security updates provide karta
hai, aur kaafi popular hai web servers aur database servers ke liye.
3. Fedora
Type: Desktop, Server
Base: Red Hat
Key Features: Cutting-edge technologies, community-driven, regular updates,
GNOME desktop
Use Case: Developers, enthusiasts, and those who want the latest features
Description: Fedora ek community-driven, cutting-edge Linux distribution hai jo Red
Hat ka upstream version hai. Fedora latest technologies aur software ko quickly adopt
karta hai aur isme new features aur improvements ka regularly integration hota hai.
Yeh developers aur enthusiasts ke liye ideal hai jo hamesha latest aur best features
chahte hain. Fedora ka default desktop environment GNOME hai, jo clean aur
modern hota hai.
4. openSUSE
Type: Desktop, Server, Enterprise
Base: Independent
Key Features: YaST configuration tool, stability, rolling release (Tumbleweed) and
regular release (Leap)
Use Case: Developers, sysadmins, enterprise environments, community-driven
projects
Description: openSUSE ek flexible aur robust distribution hai jo YaST (Yet another
Setup Tool) ka use karta hai for easy configuration of the system. Yeh enterprise
environments ke liye stability aur security provide karta hai. openSUSE ke do versions
hain:
o Leap: Stable release version, suitable for production use
o Tumbleweed: Rolling release, for those who want the latest software
openSUSE ka focus developers aur system administrators ko powerful tools provide
karne par hai.
5. Debian
Type: Desktop, Server
Base: Independent
Key Features: Stability, reliability, huge software repository, extensive package
management
Use Case: Servers, stable systems, developers
Description: Debian ek highly stable aur secure distribution hai. Debian ka reputation
hai ki yeh kaafi reliable aur crash-free hota hai. Yeh un logon ke liye ideal hai jo
stability ko prioritize karte hain. Debian ka package management system APT
(Advanced Package Tool) kaafi efficient hai, aur isme vast software repository
available hai. Debian ka use desktop aur server dono environments mein hota hai.
6. Gentoo
Type: Advanced, Desktop, Server
Base: Independent
Key Features: Source-based installation, high customizability, performance-oriented
Use Case: Advanced users, those who want to fine-tune their system
Description: Gentoo ek source-based Linux distribution hai, jisme aapko apne system
ko manually configure karna padta hai. Iska main advantage yeh hai ki aap apne
hardware aur needs ke hisaab se system ko highly optimize kar sakte hain. Gentoo ko
use karne ke liye advanced Linux knowledge aur skills chahiye hoti hain. Yeh
distribution un users ke liye best hai jo system ko deeply customize aur fine-tune
karna chahte hain.
7. Ubuntu
Type: Desktop, Server
Base: Debian
Key Features: User-friendly, large community, LTS versions, ease of use
Use Case: Beginners, developers, everyday users, servers
Description: Ubuntu sabse popular aur user-friendly Linux distribution hai, jo Debian
par based hai. Ubuntu ka main focus simplicity aur accessibility pe hai, aur isme
bohot saari applications pre-installed aati hain. Ubuntu ke paas LTS (Long Term
Support) versions hote hain, jisme 5 years tak updates milte hain. Yeh desktop aur
server dono environments mein use hota hai, aur beginners ke liye best option hai.
8. Arch Linux
Type: Advanced, Desktop
Base: Independent
Key Features: Rolling release, minimalistic, customizable, Arch Wiki, command-line
installation
Use Case: Advanced users, custom setups, enthusiasts
Description: Arch Linux ek minimalistic aur rolling release distribution hai jo flexibility
aur customization pe focus karta hai. Arch ke installation process ko command-line se
kiya jata hai, jo beginners ke liye thoda challenging ho sakta hai. Yeh distribution un
logon ke liye ideal hai jo apne system ko apni marzi ke mutabik build aur configure
karna chahte hain. Arch Wiki ek excellent documentation resource hai, jo Arch users
ke liye guide ka kaam karti hai.
9. Knoppix
Type: Live distribution, Desktop
Base: Debian
Key Features: Live CD/DVD, hardware detection, rescue system
Use Case: Live environments, system recovery, hardware testing
Description: Knoppix ek live CD/DVD Linux distribution hai jo mainly system rescue
aur hardware testing ke liye use hota hai. Aap isse USB ya CD se boot kar sakte hain
bina apne system ko install kiye. Knoppix ka use un situations mein hota hai jab aapko
apne system ko troubleshoot karna ho ya data recovery karna ho.
10. Kali Linux
Type: Security-focused
Base: Debian
Key Features: Penetration testing, security tools, ethical hacking
Use Case: Security professionals, ethical hackers, penetration testers
Description: Kali Linux ek security-focused distribution hai jo penetration testing aur
ethical hacking ke liye specially design kiya gaya hai. Isme 600+ pre-installed security
tools hote hain jo vulnerability assessment, penetration testing, aur digital forensics
ke liye use kiye jaate hain. Kali Linux ka use security professionals, hackers, aur
network administrators karte hain.
Summary:
Red Hat (RHEL): Enterprise-grade, stability, long-term support (paid).
CentOS: Free version of RHEL, suitable for servers.
Fedora: Cutting-edge features, community-driven, fast updates.
openSUSE: Flexible, stability (Leap) and latest features (Tumbleweed), YaST.
Debian: Stable, reliable, ideal for servers and critical systems.
Gentoo: Source-based, advanced users, high customizability.
Ubuntu: User-friendly, large community, great for beginners and desktops.
Arch Linux: Minimalistic, rolling release, highly customizable, advanced users.
Knoppix: Live CD, system rescue, hardware detection.
Kali Linux: Penetration testing, ethical hacking, security-focused.
Aap apne specific needs aur experience level ke hisaab se in distributions ko choose kar
sakte hain.
Linux Operating System ek open-source operating system hai jo Unix-based hai. Yeh Linux
kernel par based hai, jo ek core component hai jo hardware aur software ke beech
interaction ko manage karta hai. Linux operating system ko kaafi flexibility aur customization
ke liye jaana jata hai aur yeh desktop se lekar servers aur embedded devices tak use hota
hai.
Linux Operating System ke Key Components:
1. Linux Kernel:
o Kernel Linux OS ka sabse core part hai. Yeh hardware ko control karta hai, jaise
memory management, process scheduling, device drivers, aur file systems.
o Kernel ko Linus Torvalds ne 1991 mein develop kiya tha, aur uske baad se iska
development worldwide contributors ke through hota raha hai.
2. Shell:
o Shell ek command-line interface (CLI) hai jo user ko system ke saath interact
karne ka option deta hai. Linux shell mein Bash (Bourne Again Shell) kaafi
common hota hai.
o Shell commands ke through aap system ki settings change kar sakte hain,
programs ko run kar sakte hain, aur files manage kar sakte hain.
3. File System:
o Linux apna file system hierarchy follow karta hai, jisme / (root) directory sabse
upar hoti hai, aur uske andar subdirectories hoti hain, jaise /home, /etc, /usr,
etc.
o Linux mein har cheez file ke roop mein hoti hai — chahe wo hardware ho,
devices ho, ya directories ho.
4. System Libraries:
o Libraries wo files hoti hain jo system ke functions ko implement karne ke liye
use hoti hain. Yeh user applications aur programs ko system resources ko
access karne mein madad karte hain.
o Example: glibc (GNU C Library) ek important system library hai jo system calls
aur functions ko handle karti hai.
5. Graphical User Interface (GUI):
o Linux mein GUI optional hota hai, lekin aaj kal most distributions GUI ke saath
aati hain. X Window System aur Wayland Linux systems mein graphical
environment provide karte hain.
o GUI mein aap window managers aur desktop environments use karte hain,
jaise GNOME, KDE Plasma, XFCE, aur Cinnamon.
6. System Utilities and Applications:
o Linux OS apne system utilities aur applications ke liye open-source software ka
use karta hai. Aapko Linux mein software packages install karne aur manage
karne ke liye package managers ka use karna padta hai, jaise apt
(Debian/Ubuntu), dnf (Fedora), pacman (Arch Linux), etc.
Linux Operating System ke Features:
1. Open Source:
o Linux ek open-source operating system hai, iska matlab hai ki aap iske source
code ko freely access, modify, aur distribute kar sakte hain. Iska development
community-driven hai aur world-wide contributors ka support milta hai.
2. Free to Use:
o Linux ek free operating system hai. Aap bina kisi license fee ke ise download
aur use kar sakte hain. Har Linux distribution ka apna license agreement hota
hai, lekin most cases mein yeh free aur open-source hota hai.
3. Multi-user and Multitasking:
o Linux ek multi-user system hai, iska matlab hai ki multiple users ek time par
system ko use kar sakte hain.
o Linux multitasking bhi support karta hai, jo ek hi time par multiple processes ko
run karne ki ability deta hai.
4. Security:
o Linux kaafi secure hai, kyunki yeh strong permission-based architecture aur
user-role management follow karta hai. Har user ko apne specific resources aur
permissions milti hain, aur system ko root access ke bina critical tasks perform
karna mushkil hota hai.
o Linux mein frequent security patches aur updates milte hain.
5. Stability and Reliability:
o Linux kaafi stable aur reliable operating system hai. Yeh system crashes aur
slowdowns se bachata hai aur long uptime ke liye jaana jata hai. Isliye Linux
server environments mein kaafi popular hai.
6. Performance:
o Linux apni performance pe bhi kaafi focus karta hai. Yeh light-weight hai aur
low-resource systems pe bhi efficiently run karta hai.
o Yeh resource management aur process scheduling ko efficiently handle karta
hai, jisse performance optimized rehti hai.
7. Customization:
o Linux highly customizable hai. Aap apne needs ke hisaab se OS ko modify kar
sakte hain. Agar aapko command-line interface (CLI) ka use karna pasand hai
toh aap GUI ko disable kar sakte hain, ya phir apne desktop environment ko
change kar sakte hain.
8. Support for Multiple Architectures:
o Linux kai different architectures ko support karta hai, jaise x86, ARM, PowerPC,
etc. Isliye yeh embedded systems, mobile devices, aur high-performance
computing environments ke liye bhi suitable hai.
9. Wide Software Availability:
o Linux mein wide range of software applications available hai, jo open-source
aur free hain. Popular software tools jaise LibreOffice, GIMP, Firefox, VLC, aur
Thunderbird Linux ke liye available hain.
o Linux mein software installation kaafi easy hai, aur aap package managers se
easily install kar sakte hain.
Linux Operating System ke Versions (Distributions):
Linux ka ek major feature yeh hai ki iske multiple versions (known as distributions) available
hain. Har distribution apne specific use cases, user base, aur features ke liye design ki gayi
hoti hai. Kuch popular Linux distributions hain:
Ubuntu: Easy-to-use, beginner-friendly, popular for desktops.
Fedora: Cutting-edge software, developer-focused.
Debian: Stability, security, used for servers and desktops.
CentOS: Free version of RHEL, used for servers.
Arch Linux: Minimalist, rolling release, for advanced users.
Kali Linux: Security-focused, penetration testing tools.
Linux Mint: Windows-like interface, for beginners.
openSUSE: Flexible, for developers and sysadmins.
Linux ka Use Cases:
1. Servers:
o Linux kaafi popular hai web servers, database servers, aur file servers ke liye.
Apache, Nginx, MySQL, aur PostgreSQL jaise servers Linux par efficiently run
karte hain.
2. Desktops:
o Linux ka use desktop computing ke liye bhi hota hai. Ubuntu, Linux Mint, aur
Fedora jaise distributions desktop users ke liye best hai, jo Windows ya macOS
se transition karna chahte hain.
3. Embedded Systems:
o Linux ko embedded systems aur Internet of Things (IoT) devices mein bhi use
kiya jata hai. Android OS bhi Linux par based hai.
4. Development:
o Linux developers ke liye ideal platform hai, kyunki yeh command-line tools,
programming languages, aur libraries ka support karta hai. Yeh development
aur testing environments mein kaafi widely use hota hai.
5. Security and Penetration Testing:
o Kali Linux jaise distributions ethical hacking aur penetration testing ke liye
specially designed hain.
Conclusion:
Linux ek powerful, open-source, aur versatile operating system hai jo wide range of
applications mein use hota hai, from personal computers to high-performance servers and
embedded systems. Yeh system stability, security, aur customization ke liye jaana jata hai.
Agar aapko apni system ko customize karna hai, ya aapko ek highly reliable aur secure OS
chahiye, toh Linux ek best choice ho sakta hai.
Disadvantages of Linux:
1. Software Compatibility:
o Linux kuch proprietary software jaise Adobe Photoshop, Microsoft Office,
AutoCAD, etc. ko support nahi karta hai. Agar aapko in applications ki zarurat
ho toh aapko alternatives (jaise GIMP, LibreOffice) ya Wine (Windows
applications ko run karne ka tool) ka use karna padta hai.
o Gaming bhi Linux par utna prevalent nahi hai, lekin gaming market ab gradually
grow kar raha hai (Steam for Linux).
2. Hardware Compatibility:
o Linux ko kuch newer hardware components ke liye support issues ho sakte
hain, jisme device drivers ki kami hoti hai. Jaise ki latest graphics cards,
printers, or Wi-Fi cards ke liye drivers ka installation problematic ho sakta hai.
o Hardware manufacturers zyada tar Linux drivers provide nahi karte hain, isliye
aapko community-supported drivers ya third-party solutions use karne padte
hain.
3. Learning Curve:
o Linux beginners ke liye initially thoda challenging ho sakta hai, khaas kar un
users ke liye jo Windows ya macOS ke accustomed hain. Command-line
interface (CLI) ka extensive use Linux mein bohot common hai.
o Aapko terminal commands aur system administration skills seekhne ki zarurat
hoti hai, especially if you are using distributions like Arch Linux or Gentoo.
4. Limited Commercial Support:
o Linux ko commercial support kaafi limited hota hai, especially agar aap free
distributions jaise Debian ya Ubuntu use karte hain. Although, Red Hat aur
SUSE jaise distributions commercial support provide karte hain, lekin unka cost
bhi hota hai.
5. Compatibility with Windows-based Applications:
o Agar aapko Windows-specific applications chahiye, toh Linux mein unhe run
karna thoda complicated ho sakta hai. Aapko dual-booting ya virtual machines
ka use karna padta hai, ya phir Wine aur PlayOnLinux jaise tools ka use karna
padta hai.
Features of Linux:
1. Multitasking:
o Linux ek multitasking operating system hai, jisme aap ek waqt par multiple
processes ko efficiently run kar sakte hain.
2. Multi-user System:
o Linux mein multiple users simultaneously system ka use kar sakte hain without
affecting each other's work. Har user ko separate resources aur permissions
milti hain.
3. Portability:
o Linux hardware architectures pe kaafi portable hai, jaise x86, ARM, PowerPC,
etc.
4. Security:
o Linux mein strong file permissions aur security protocols hote hain jo system
ko secure rakhtay hain. Root user aur sudo user ke permissions ko effectively
manage kiya jata hai.
5. Networking:
o Linux ka networking kaafi strong hai, aur aap easily remote servers ko manage
kar sakte hain via SSH. Iske alawa, Linux advanced networking tools provide
karta hai jaise iptables, ipconfig, etc.
6. Package Management:
o Linux mein package managers hotay hain, jaise apt, yum, dnf, pacman, jo
software installation aur updates ko easy bana dete hain.
7. Support for Multiple File Systems:
o Linux ext4, XFS, Btrfs, NTFS, aur FAT jaise multiple file systems ko support karta
hai.
Functions of Linux:
1. Process Management:
o Linux mein process management kaafi efficient hoti hai. Yeh processes ko
schedule karta hai, unki memory allocation ko manage karta hai, aur unki
execution ko monitor karta hai.
2. Memory Management:
o Linux memory ko efficiently allocate karta hai aur unused memory ko free kar
deta hai, taaki system resources ka waste na ho. Virtual memory aur paging
Linux mein memory management ko smooth banate hain.
3. Device Management:
o Linux hardware devices ko manage karta hai, jaise keyboard, mouse, printer,
disk drives, network interfaces, etc. Yeh device drivers ko load karta hai aur
device communication ko handle karta hai.
4. File System Management:
o Linux file system ko manage karta hai. Yeh directories aur files ko organize karta
hai, aur file operations (read, write, delete) ko perform karta hai.
5. User Management:
o Linux mein user accounts aur permissions ko manage kiya jata hai. Yeh system
mein security aur privacy maintain karta hai, aur ek multi-user environment ko
manage karta hai.
6. Security Management:
o Linux mein security functions bhi critical hote hain. Yeh system ko
vulnerabilities se protect karta hai aur firewalls, SELinux, aur AppArmor jaisi
security features ko implement karta hai.
7. Networking Functions:
o Linux networking tools ko handle karta hai. Yeh routing, firewalls, SSH, aur DNS
configurations ko manage karta hai aur multiple devices ko communicate karne
mein madad karta hai.
Conclusion:
Linux ek versatile, stable, aur secure operating system hai. Iske advantages, features, aur
functions kaafi impressive hain, lekin kuch disadvantages bhi hain, jisme software
compatibility aur hardware support shamil hain. Lekin, agar aapko flexibility, customization,
aur reliability ki zarurat hai, toh Linux ek excellent choice ho sakta hai.
LINUX ARCHITECTURE :
The main components of Linux operating system are: Application, Shell, Kernel, Hardware,
Utilities
Linux Operating System ke main components hain: Application, Shell, Kernel, Hardware,
aur Utilities. In components ka apna specific role hota hai, jo milke Linux ko ek stable,
efficient, aur customizable operating system banate hain. Aaiye, in components ko detail
mein samajhte hain:
1. Hardware:
Hardware wo physical components hain jinke upar Linux operating system run karta hai. Ye
Linux ke liye base layer hai, jahan pe sab processes aur tasks physically executed hote hain.
Examples:
o CPU (Central Processing Unit): Ye computing tasks ko process karta hai aur
instructions ko execute karta hai.
o Memory (RAM): Temporary storage hai, jahan active processes aur data store
hote hain.
o Hard Drive: Permanent storage device, jahan data, files, programs, aur the
operating system stored hota hai.
o Input/Output Devices: Keyboard, mouse, monitor, printers, etc., jo user se
input lene aur output dene ka kaam karte hain.
Role in Linux: Hardware Linux ke kernel ke saath interact karta hai. Kernel hardware
resources ko manage karta hai aur unhe user space mein accessible banata hai.
2. Kernel:
Kernel Linux ka core part hai, jo hardware aur software ke beech interface ka kaam karta
hai. Kernel system ke sare basic functions ko control karta hai, jaise process management,
memory management, device management, aur file system management.
Main Functions of the Kernel:
Process Management: Kernel active processes ko schedule karta hai, unki execution
ko manage karta hai, aur processes ke beech resources allocate karta hai.
Memory Management: Kernel RAM aur virtual memory ko manage karta hai. Yeh
memory allocation, deallocation, aur swapping operations ko handle karta hai.
Device Management: Kernel hardware devices ko manage karta hai (jaise disk drives,
printers, graphics cards) through device drivers. Yeh communication kernel aur
hardware ke beech establish karta hai.
File System Management: Kernel file systems ko manage karta hai, jaise ext4, XFS,
Btrfs, etc. Yeh file storage, retrieval, aur modification ka process control karta hai.
Security: Kernel system ko secure rakhta hai. Yeh user access controls aur permissions
set karta hai taaki system ke resources unauthorized users se protected rahe.
Kernel Types:
Monolithic Kernel: Linux ka kernel monolithic hai, matlab saare kernel functions ek hi
module mein include hote hain.
Microkernel: Yeh kernel ka ek simplified version hota hai, jisme minimum core
functions hote hain aur baaki functions user space mein run karte hain.
3. Shell:
Shell ek command-line interface (CLI) hai jo user ko system ke saath interact karne ka
method provide karta hai. Shell, user commands ko read karta hai, unhe interpret karta hai,
aur phir appropriate action perform karta hai.
Types of Shells:
Bash (Bourne Again Shell): Sabse popular shell hai Linux mein. Yeh Linux ke default
shell environment ke roop mein use hota hai.
Zsh (Z Shell): Bash ka ek advanced version, jo additional features jaise auto-
completion aur improved scripting capabilities provide karta hai.
Fish Shell: User-friendly shell, jo suggestions aur syntax highlighting provide karta hai.
Main Functions of the Shell:
Command Interpretation: Shell user input ko interpret karta hai aur kernel ke system
calls ke zariye instructions execute karta hai.
Scripting: Shell mein aap scripts likh sakte hain jo repetitive tasks ko automate karte
hain. Yeh bash scripting ke zariye ho sakta hai.
File Management: Shell commands ke through aap files ko create, delete, move,
copy, aur modify kar sakte hain.
Role in Linux: Shell ek interface ke roop mein kaam karta hai, jahan user commands likhte
hain aur Linux kernel ko execute karne ke liye instructions dete hain.
4. Utilities:
Utilities wo programs hain jo Linux operating system ke maintenance, management aur
basic tasks ko perform karte hain. Yeh user applications ke basic tools hote hain jo system
ko efficient aur functional banate hain.
Examples of Utilities:
File Management Utilities: Jaise cp (copy), mv (move), rm (remove), ls (list), etc. Yeh
tools aapko files aur directories manage karne mein madad karte hain.
System Monitoring Utilities: Jaise top, ps, df, du, free, etc. Yeh utilities system
resources, processes, aur memory usage ko monitor karne mein help karte hain.
Networking Utilities: Jaise ping, ifconfig, netstat, ssh, scp, etc. Yeh tools network
connections ko manage aur troubleshoot karte hain.
Package Management Utilities: Jaise apt (Debian-based systems ke liye), yum (Red
Hat-based systems ke liye), pacman (Arch Linux ke liye), etc. Yeh tools system mein
software install, update aur manage karte hain.
Role in Linux: Utilities Linux ko user-friendly aur efficient banate hain. Yeh system ko
customize karne, manage karne aur troubleshoot karne mein madad karte hain. Utilities
shell ke saath integrate ho kar system-level tasks ko automate aur manage karte hain.
5. Application:
Applications wo software programs hain jo user space mein run karte hain aur directly users
ke interactions ko handle karte hain. Yeh programs end-users ke liye designed hote hain aur
system ke core functions ko perform nahi karte.
Examples of Applications:
Web Browsers: Jaise Firefox, Google Chrome. Yeh applications internet browsing ke
liye use hoti hain.
Office Suites: Jaise LibreOffice, OpenOffice. Yeh office tasks (word processing,
spreadsheet, etc.) perform karte hain.
Media Players: Jaise VLC Media Player, MPlayer. Yeh audio aur video files ko play
karne ke liye use hoti hain.
Graphics Editing: Jaise GIMP (image editing), Inkscape (vector graphics).
Games and Development Tools: Linux mein games, programming IDEs (Integrated
Development Environments), aur development tools bhi available hain.
Role in Linux: Applications user ke tasks ko simplify karte hain aur system ke functionalities
ko extend karte hain. Yeh directly user ke interaction ke liye hoti hain, aur system resources
ko use karne ke liye kernel aur utilities ke saath interact karti hain.
Conclusion:
1. Hardware: Physical components, jaise CPU, memory, disk drives, jo system ko run
karte hain.
2. Kernel: Core component, jo system resources ko manage karta hai aur hardware aur
user space ke beech communication establish karta hai.
3. Shell: Command-line interface jo user ko system ke saath interact karne ka method
provide karta hai.
4. Utilities: Tools jo system management, maintenance aur basic tasks ko perform karte
hain.
5. Applications: User-specific programs jo tasks perform karte hain jaise browsing,
editing, media playback, etc.
Yeh components milke Linux operating system ko ek powerful, customizable, aur user-
friendly platform banate hain.
UNIX ENVIRONMENT :
Standalone Personal Environment, Time-Sharing Environment, aur Client-Server
Environment ye sab alag-alag types ke computing environments hain jo systems ke
operations ko define karte hain. In environments ka use kaafi different use cases aur tasks
ke liye hota hai. Aaiye, in tino environments ko samajhte hain:
3. Client-Server Environment:
A Client-Server Environment ek network architecture hai jisme ek server centralized system
ke roop mein kaam karta hai aur multiple clients us server se services aur resources access
karte hain. Is environment mein, server central data, services, aur resources ko store aur
manage karta hai, jabki clients un resources ko request karte hain aur unka use karte hain.
Characteristics:
Separation of Roles: Client-server architecture mein clear separation hoti hai, jahan
client requests send karta hai aur server un requests ko process karke response deta
hai.
Centralized Server: Server ek powerful machine hoti hai jo centralized services, data,
aur applications ko manage karti hai. Clients distributed hote hain aur server se
remotely interact karte hain.
Networking: Clients aur server ke beech communication network ke through hota
hai, jisme protocols like HTTP, FTP, and TCP/IP ka use hota hai.
Scalability: Server ko powerful aur scalable banaya ja sakta hai, jabki clients ka
hardware comparatively simple ho sakta hai.
Example:
Web-based Applications: Websites (like Gmail or Facebook) jahan server client
requests (browser) ko handle karta hai aur user interface ko show karta hai.
Database Systems: Client machines database server se data request karte hain aur
server un requests ko process karta hai.
File Sharing Systems: Networked systems where clients share files stored on a server.
Advantages:
Centralized Management: Server central location pe rehta hai, jahan se data aur
services easily manage kiye ja sakte hain.
Resource Sharing: Clients server se resources jaise files, databases, and applications
share karte hain.
Security: Server pe security control zyada hota hai, jisme data encryption aur access
control mechanisms use kiye ja sakte hain.
Scalability: Server ko easily upgrade ya scale kiya ja sakta hai, aur new clients ko
system se connect kiya ja sakta hai.
Disadvantages:
Dependency on Server: Agar server down ho jata hai, toh clients ko services access
karne mein problem ho sakti hai.
Network Congestion: Agar zyada clients ek time par server se interact karte hain, toh
network bandwidth issues aa sakte hain.
Server Maintenance: Server ko continuous monitoring aur maintenance ki zarurat
hoti hai, jisme regular updates aur backups include hote hain.
Summary of Differences:
Standalone Personal Client-Server
Feature Time-Sharing Environment
Environment Environment
Multiple clients access
Multiple users, each gets
User Access Single user. centralized server
CPU time.
services.
Local resources, Server provides
System Shared resources, CPU time
dedicated to a single resources to clients over
Resources is divided.
user. a network.
Network-dependent,
Network Network may be used for
No network required. clients connect to a
Dependency remote users.
server.
Web applications, file
Personal computing Suitable for multi-user
Usage sharing, centralized
tasks. environments.
services.
Mainframe systems, UNIX or Websites, database
Personal computer or
Example Linux in multi-user systems, file sharing
laptop.
environments. systems.
Conclusion:
Standalone Personal Environment ek single user ke liye hota hai jahan system
resources dedicated hote hain.
Time-Sharing Environment mein multiple users ek hi system pe time share karte
hain, aur ek time slice basis pe CPU time allocate hota hai.
Client-Server Environment mein server centralized resources aur services provide
karta hai, aur clients un resources ko remotely access karte hain, typically over a
network.
Har environment apne specific use cases aur requirements ke liye design kiya gaya hai, aur
unka use cases jaise individual work, multi-user systems, aur networked applications ko
support karte hain.
ACCESSING LINUX SYSTEM:
Accessing a Linux system ka matlab hai, kisi bhi Linux-based operating system ko apne
resources, files, aur functionalities ko use karne ke liye login ya interact karna. Linux system
ko access karne ke kai tareeqe hote hain, jaise local access aur remote access. Iska purpose
hai ki aap apne system ke andar available resources ko efficiently use kar sakein.
Linux System Access Methods:
Summary:
1. Local Access: Directly apne Linux system pe login karna, chaahe aap graphical
interface (GUI) ya command line interface (CLI) ka use karein.
2. Remote Access:
o SSH (Secure Shell): Remote CLI access for Linux systems.
o VNC: Remote desktop access for graphical interface.
o RDP: Remote desktop access (primarily for Windows, but can be used for Linux
too).
o FTP/SFTP: File transfer access.
3. Graphical User Interface (GUI) Access: Desktop environment ke through system ko
access karna.
4. TTY (Teletype Terminal): Direct terminal access through virtual consoles.
In different scenarios, aapko different methods use karni padti hain depending on whether
you're accessing your Linux system locally or remotely.
Linux system ko start aur shut down karna basic tasks hain jo har user ko seekhni chahiye.
Ye tasks aap command line interface (CLI) aur graphical user interface (GUI) dono se
perform kar sakte hain. Aaiye, har method ko detail mein samajhte hain:
4. Scheduling a Shutdown:
Agar aap chahte hain ki system ko ek specific time pe shutdown kiya jaye, toh aap shutdown
command ke sath time specify kar sakte hain.
Example:
Shutdown after 15 minutes:
sudo shutdown -h +15
Yeh command system ko 15 minutes baad shutdown kar dega.
Shutdown at a specific time:
sudo shutdown -h 23:30
Yeh command system ko 11:30 PM pe shutdown kar dega.
Summary:
1. Starting a Linux System:
o Power on your system and wait for it to boot. After boot, login with your
username and password.
2. Shutting Down a Linux System:
o GUI Method: Click on the system menu, select Shutdown or Power Off, and
confirm.
o CLI Method:
sudo shutdown -h now: Shutdown immediately.
sudo poweroff: Power off immediately.
sudo reboot: Restart system.
sudo systemctl poweroff: Shutdown using systemd.
In dono methods se aap apne Linux system ko safely start aur shutdown kar sakte hain.
Linux mein login aur logout karna simple aur important tasks hain. Ye tasks aap Graphical
User Interface (GUI) aur Command Line Interface (CLI) dono se perform kar sakte hain.
Aaiye, in dono methods ko step-by-step samajhte hain:
Summary:
1. Login:
o GUI Method: Apne username aur password ke saath login screen par login
karein.
o CLI Method: login command ke saath username aur password enter karein.
2. Logout:
o GUI Method: System menu se Logout option select karein.
o CLI Method: logout ya exit command ka use karein.
3. Switching Users: Agar aapko logout kiye bina user switch karna ho, toh su ya sudo
command ka use karein.
Ye processes aapko apne Linux system mein login aur logout karne mein madad karenge,
chahe aap GUI use kar rahe ho ya command line interface (CLI) ke through kaam kar rahe
ho.
Unit 3
FILE SYSTEM:
Linux ka file system wo tarika hota hai jisme Linux operating system apne data ko organize
karta hai aur store karta hai. Ye ek hierarchical structure hota hai, jisme sabhi files aur
directories ek tree structure mein organize hoti hain.
Linux ka file system kuch key features ke saath aata hai:
1. Root Directory ("/"): Sabse upar ka level hota hai, jo root directory ke naam se jaana
jata hai. Iske andar baaki sari directories aur files hoti hain.
2. Hierarchical Structure: Linux mein sabhi files aur directories ek tree-like structure
mein hoti hain. Jaise /home, /etc, /var, etc.
3. Mounting: Linux mein different storage devices jaise hard drives, USB drives ko
specific directories mein "mount" kiya jata hai. Matlab, wo devices us directory ke
under aajaate hain.
4. Permissions: Har file aur directory pe permissions set hoti hain, jo determine karti
hain ki kaun si users ya groups ko access milta hai.
5. File Types: Linux mein alag-alag file types hote hain, jaise regular files, directories,
symbolic links, etc.
Example of common directories in Linux:
/bin: Essential system binaries (commands).
/home: User-specific data and files (e.g., /home/username).
/etc: System configuration files.
/var: Variable data like logs, databases, etc.
/tmp: Temporary files.
Is tarah se Linux ka file system kaafi flexible aur organized hota hai.
LINUX FILES :
Linux mein "files" wo basic units hoti hain jisme data store kiya jata hai. Linux file system
mein, sab kuch ek file ke roop mein represent hota hai, chahe wo regular data ho,
configuration files ho, ya system resources ho. Linux mein file types bhi kaafi different hote
hain.
Linux mein different types ki files:
1. Regular Files: Ye wo files hoti hain jisme actual data store hota hai, jaise text files,
image files, audio files, etc.
o Example: /home/user/document.txt
2. Directory Files: Ye files wo directories hoti hain jo other files ya directories ko contain
karti hain.
o Example: /home/user (jo sub-directories aur files ko contain karta hai).
3. Special Files: Ye system-level files hoti hain jo hardware devices ko represent karti
hain, jaise hard drives, printers, etc. Inhe device files bhi kaha jata hai.
o Example: /dev/sda (jo hard drive ko represent karta hai).
4. Symbolic Links: Ye files hoti hain jo kisi dusri file ya directory ka reference hoti hain.
Inko shortcut ki tarah samjha ja sakta hai.
o Example: /home/user/link_to_file (jo kisi aur file ka reference ho sakti hai).
5. Named Pipes (FIFOs): Ye special files hoti hain jo inter-process communication ke liye
use hoti hain.
o Example: /tmp/pipe
6. Socket Files: Ye files networking ke liye use hoti hain aur processes ke beech
communication ke liye hoti hain.
o Example: /var/run/socket_file
7. Block Devices: Ye devices files hoti hain jo block-level data ko handle karti hain, jaise
hard drives ya USB drives.
o Example: /dev/sda
8. Character Devices: Ye files hardware devices ko represent karti hain jo byte-by-byte
data handle karti hain, jaise serial ports, printers, etc.
o Example: /dev/tty1
Important Concepts:
File Permissions: Har file pe permissions set hoti hain, jaise read, write, execute. Ye
determine karti hain ki kaun file ko access kar sakta hai.
Ownership: Har file ka ek owner hota hai, jo usually us file ko create karta hai, aur us
file ko ek group bhi assign hota hai.
File Path: Har file ka ek unique path hota hai jo usko identify karta hai, jaise
/home/user/file.txt.
Is tarah se, Linux mein sab kuch file ke roop mein organize hota hai, chahe wo user data ho,
system configuration ho, ya devices ho.
LINUX INODES:
Linux mein inode ek data structure hota hai jo har file ya directory ke baare mein
information store karta hai, lekin file ka actual content usme nahi hota. Inode file system ke
internal structure ka part hota hai aur yeh file ke metadata ko store karta hai.
Inode mein kya-kya information hoti hai?
1. File Type: Ye batata hai ki file ka type kya hai (regular file, directory, symbolic link,
etc.).
2. Permissions: File ke upar read, write, aur execute permissions ko store karta hai.
Matlab, kaun user ya group is file ko access kar sakta hai.
3. Owner: File ka owner kaun hai (user ID).
4. Group: File kis group ka part hai (group ID).
5. Size: File ka size kitna hai (in bytes).
6. Timestamps:
o Creation Time (ctime): Jab file create hui thi ya last time inode me changes kiye
gaye the.
o Modification Time (mtime): Jab file ka content last time modify kiya gaya.
o Access Time (atime): Jab file ko last time access kiya gaya tha.
7. Link Count: Ye batata hai ki kitne hard links file ke liye exist karte hain.
8. Pointers to Data Blocks: Inode actual file data ki location ko point karta hai. Ye
pointers file ke data blocks ke address hote hain, jahan par file ka content physically
store hota hai.
Inode ka kaise kaam karta hai?
Jab aap kisi file ko create karte hain, system ek naya inode allocate karta hai aur usme
file ke metadata ko store karta hai.
Jab aap kisi file ko access karte hain, system inode ke through file ke metadata ko
check karta hai aur file data blocks ko retrieve karta hai.
Example:
Agar ek file ka path hai /home/user/file.txt, to file ka inode is tarah work karega:
File ka actual content disk ke kisi block me store hoga.
Inode is file ka metadata store karega, jaise file ke size, permissions, owner, aur us
data block ka address jahan actual content rakha hai.
Inodes ka Limit:
Har file system mein ek fixed number of inodes hoti hain, jo file system ke creation ke time
define kiya jata hai. Agar inodes khatam ho jaati hain, to aap new files nahi create kar sakte,
chahe disk space available ho.
Inodes kaise dekhte hain?
Aap ls -i command ka use karke kisi file ka inode number dekh sakte hain.
Example:
$ ls -i /home/user/file.txt
123456 /home/user/file.txt
Yahaan 123456 inode number hai file ka.
In short, inodes file system ka ek important part hain jo file ke metadata ko manage karte
hain, aur file ke content ko access karne ka mechanism define karte hain.
STRUCTURE OF FILE SYSTEM:
Linux file system ka structure ek hierarchical aur organized system hota hai, jisme different
types ki files aur directories hoti hain, jo ek tree-like structure mein arranged hoti hain. Is
structure ko samajhna zaroori hai, kyunki isse aapko pata chal sakta hai ki system ke data ko
kaise organize aur manage kiya jata hai.
File System ka Basic Structure:
1. Root Directory ("/"):
o Linux file system ka top-level directory hota hai.
o Har cheez root directory ke andar hoti hai.
o Sabhi directories aur files root directory ke andar nested hoti hain.
o Root directory ko "slash" ("/") se represent kiya jata hai.
2. Directories:
o Linux mein directories kaafi important role play karti hain.
o Har directory apne andar files aur sub-directories ko contain karti hai.
o Linux ka file system directories ka hierarchical structure hota hai, jo ek tree
jaisa dikhta hai.
Common Directories in Linux File System:
1. /bin:
o Is directory mein essential system binaries (commands) stored hoti hain jo
system ke normal functioning ke liye zaroori hoti hain.
o Example: ls, cp, cat.
2. /boot:
o Is directory mein boot-related files hoti hain, jaise kernel images aur
bootloader configuration files.
3. /dev:
o Ye directory system ke devices (hardware) ko represent karti hai.
o Example: /dev/sda (hard drive), /dev/tty1 (console).
4. /etc:
o Is directory mein system configuration files stored hoti hain.
o Example: /etc/passwd (user data), /etc/fstab (file systems ko mount karne ki
configuration).
5. /home:
o Ye directory user-specific files aur data ko store karti hai.
o Har user ka apna directory hota hai is folder ke andar.
o Example: /home/user1, /home/user2.
6. /lib:
o Is directory mein system libraries stored hoti hain jo programs ko chalane ke
liye zaroori hoti hain.
o Example: /lib/libc.so (C library).
7. /media:
o Ye directory removable media devices, jaise USB drives, CDs, DVDs ko mount
karne ke liye use hoti hai.
o Example: /media/usb
8. /mnt:
o Is directory ka use temporary mounting ke liye kiya jata hai.
o Example: /mnt/disk
9. /opt:
o Is directory mein optional application software packages store hote hain jo
system ke outside install kiye jate hain.
o Example: /opt/google
10./proc:
Is directory mein system processes aur kernel-related information virtual files ke roop
mein store hoti hai.
Example: /proc/cpuinfo (CPU information).
11./root:
Ye directory superuser (root) ka home directory hota hai.
12./sbin:
Is directory mein system binaries hoti hain, jo typically system administration tasks ke
liye use hoti hain (root user ke liye).
Example: shutdown, reboot.
13./srv:
Is directory mein services se related data stored hota hai.
Example: /srv/www (web server content).
14./sys:
Ye directory system aur kernel ke virtual files ka container hota hai, jisme system ke
state aur kernel parameters ki information hoti hai.
Example: /sys/class/net (network devices ki details).
15./tmp:
Temporary files ka storage location hota hai.
Example: /tmp/tempfile
16./usr:
Is directory mein user-related applications aur programs stored hote hain.
Example: /usr/bin (user binaries), /usr/lib (libraries).
17./var:
Is directory mein variable data stored hota hai, jaise logs, databases, emails, etc.
Example: /var/log (system logs).
Linux File System Hierarchy:
/
├── bin
├── boot
├── dev
├── etc
├── home
│ ├── user1
│ ├── user2
├── lib
├── media
├── mnt
├── opt
├── proc
├── root
├── sbin
├── srv
├── sys
├── tmp
├── usr
└── var
Key Points:
Tree-like Structure: Linux file system ek tree-like structure mein hota hai, jahan root
directory sabse upar hoti hai aur baaki sab directories uske under nested hoti hain.
Mounting: Alag-alag file systems ko ek specific directory mein mount kiya jata hai
(e.g., /mnt ya /media mein).
File System Types: Linux mein alag-alag file systems (jese ext4, xfs, btrfs) use kiye ja
sakte hain, jo data storage aur access ko manage karte hain.
Is tarah, Linux ka file system ek well-organized aur efficient structure provide karta hai, jo
data ko manage karna aur system ko secure aur maintainable banane mein madad karta hai.
DIFFERNCE INODES OR STRUCTURE OF FILE SYSTEM :
Key Differences:
Aspect Inodes File System Structure
File system structure wo organizational
Inode ek data structure hota hai jo
Definition layout hai jo files aur directories ko
file ka metadata store karta hai.
manage karta hai.
Inode file ka metadata manage
File system structure files aur directories
Function karta hai, jaise permissions, size,
ko organize karne ka kaam karta hai.
timestamps, etc.
Inode file ke metadata aur data File system structure files ko ek tree-like
Storage
blocks ke location ko store karta hai. hierarchy mein organize karta hai.
Inode mein file ka actual content File system structure directories aur files
Content
nahi hota, bas metadata hota hai. ka logical structure hota hai.
Inode number, jise ls -i se dekha ja
Example Root directory (/), /home, /etc, etc.
sakta hai.
Inodes file system ke andar ek part File system structure ek overall
Dependency hote hain, jo file ka metadata store framework hai jo files aur directories ko
karte hain. organize karta hai.
In Simple Terms:
Inodes ka kaam file ke metadata ko manage karna hai, jisme file ka size, permissions,
owner, aur data blocks ke locations ki information hoti hai.
File System Structure ka kaam poore organization ko define karna hai, jisme
directories aur files ka hierarchy banaya jata hai. Iska goal hai files ko logically aur
efficiently store karna.
Dono hi ek dusre ke saath kaam karte hain, jisse file system ko manage karna aur data ko
access karna efficient hota hai.
FILE SYSTEM COMPONENTS :
File system ke components wo different elements hote hain jo milke file system ko structure
karte hain, manage karte hain, aur file storage aur access ko efficient banate hain. Linux file
system mein kuch key components hote hain jo ek file system ko functional banate hain.
Chaliye unko dekhte hain:
Chaliye, Data Blocks, Superblock, aur Inodes ko detail mein samajhte hain. Ye sab file
system ke core components hain, aur har ek ka apna important role hota hai. Inko ache se
samajhna zaroori hai, kyunki ye system ke data ko store karne, access karne aur manage
karne mein madad karte hain.
1. Inodes:
Definition:
o Inode ek data structure hota hai jo file ya directory ke metadata ko store karta
hai. Inode ka kaam file ka actual content store karna nahi hai, balki us file ke
baare mein zaroori information (metadata) ko store karna hai.
Information Stored in Inodes:
o File Type: Ye batata hai ki file ka type kya hai (regular file, directory, symbolic
link, etc.).
o Permissions: File ko kaun read, write, aur execute kar sakta hai (permissions).
o Owner and Group: File ka owner aur wo group jo file se related hai (user ID aur
group ID).
o File Size: File ka size (bytes mein).
o Timestamps:
Creation Time (ctime): Jab file create hui thi ya inode mein changes kiye
gaye the.
Modification Time (mtime): Jab file ka content modify kiya gaya tha.
Access Time (atime): Jab file ko last time access kiya gaya tha.
o Link Count: Kitne hard links file ke liye exist karte hain.
o Pointers to Data Blocks: Ye pointers actual file content ko point karte hain jo
data blocks mein stored hota hai.
Function of Inodes:
o Jab aap kisi file ko access karte hain, system pehle inode ko access karta hai,
uske baad data blocks ko retrieve karta hai.
o Inode file ka unique identifier hota hai, aur ye file system ko track karne mein
madad karta hai ki kis file ka content kahaan stored hai.
Example:
o Agar aap ls -i command run karte hain, to aapko file ka inode number dikhega.
Har file ka ek unique inode number hota hai.
$ ls -i /home/user/file.txt
123456 /home/user/file.txt
Yahaan 123456 inode number hai jo file ka unique identifier hai.
2. Data Blocks:
Definition:
o Data blocks wo actual physical storage units hote hain jahan file ka content
store hota hai. Har file ka data disk ke blocks mein store hota hai.
Role of Data Blocks:
o Agar file ka size bada hai, to us file ka data multiple blocks mein divided hota
hai.
o Data blocks ka primary role hai file ke content ko store karna. Ye blocks disk pe
physically allocate hote hain aur inhe inode ke through track kiya jata hai.
Types of Data Block Pointers:
o Direct Pointers: Ye pointers directly data blocks ki taraf point karte hain.
o Indirect Pointers: Agar file ka size bohot bada hai, to inode mein ek pointer ek
additional block ki taraf point karta hai jo aur data block pointers store karta
hai.
o Double Indirect Pointers: Ye pointer ek aur level deep jaake blocks ko point
karta hai.
o Triple Indirect Pointers: Ye pointers multiple levels deep jaake data blocks ke
addresses ko store karte hain.
Function:
o Jab file ka data read ya write hota hai, to file system inode se data block ke
addresses ko retrieve karta hai aur phir actual data ko access karta hai.
3. Superblock:
Definition:
o Superblock file system ka ek key component hota hai jo file system ki overall
information store karta hai. Ye file system ke "health" aur structure ko track
karta hai.
Information Stored in Superblock:
o File System Type: File system ka type kya hai (e.g., ext4, xfs, btrfs, etc.).
o Total Number of Inodes: File system mein kitne total inodes available hain.
o Total Number of Blocks: File system mein kitne total data blocks available hain.
o Free Inodes: Kitne free inodes available hain (jahan new files create ki ja sakti
hain).
o Free Blocks: Kitne free data blocks available hain (jahan new file ka data store
kiya ja sakta hai).
o Mount Information: File system kis mount point pe mounted hai aur kis device
pe located hai.
o File System Status: File system ka status (clean ya dirty). Agar system crash
hota hai, to superblock se pata chalta hai ki file system ka consistency check
karna zaroori hai ya nahi.
Function:
o Superblock ka main kaam file system ke overall structure ko manage karna aur
monitor karna hota hai. Agar superblock corrupt ho jata hai, to file system ke
operations kaafi impact ho sakte hain.
o Superblock file system ko mount karte waqt zaroori information provide karta
hai, jaise total blocks aur available space.
Example:
o Agar file system ka superblock corrupt ho jata hai, to aap fsck command ka use
karke file system ko repair kar sakte hain. fsck file system ke integrity ko check
karta hai aur errors ko fix karta hai.
Summary of Roles:
Component Role
File ke metadata ko store karta hai (permissions, owner, timestamps, etc.). File
Inodes
ke data blocks ke locations ko track karta hai.
Data Blocks File ka actual content store karte hain. Ye disk pe physically allocate hote hain.
File system ka overall information store karta hai (total inodes, free blocks, file
Superblock
system status). File system ke mount aur status ko manage karta hai.
Visual Overview:
File System Layout:
-----------------------------------------------------
| Superblock | <-- System-wide info like total blocks, free space
-----------------------------------------------------
| Inode 1 | Inode 2 | Inode 3 | ... | Inode n | <-- Contains metadata like permissions,
owner
-----------------------------------------------------
| Data Block 1 | Data Block 2 | ... | Data Block n | <-- Actual file content (data)
-----------------------------------------------------
Key Takeaways:
Inodes manage file metadata (permissions, size, timestamps, etc.).
Data Blocks store the actual file content.
Superblock contains critical information about the entire file system, ensuring proper
functioning and structure.
In short, ye sab components milke file system ko organize karte hain aur data ko efficiently
store, access, aur manage karte hain.
STANDARD FILE SYSTEM :
Root aur Swap file systems Linux mein important roles play karte hain. Dono ka apna
specific use case aur function hai. Chaliye, inko detail mein samajhte hain:
1. Root File System (/):
Definition:
o Root file system (yaani / file system) wo file system hai jo Linux operating
system ke sabhi core files aur directories ko contain karta hai. Iska naam root
isliye rakha gaya hai kyunki ye file system ka sabse upar ka level hota hai, jisme
baaki sab directories and files logically organized hote hain.
o Ye file system Linux OS ke core components ko store karta hai, jaise kernel,
system binaries, libraries, device files, configurations, aur log files.
Key Directories under / (Root Directory):
o /bin: Basic system binaries (commands).
o /boot: Boot loader files, kernel, etc.
o /dev: Device files (e.g., hard drives, USBs).
o /etc: Configuration files for system and software.
o /home: User home directories (where personal files are stored).
o /lib: Shared libraries needed by binaries in /bin and /sbin.
o /mnt: Temporarily mounted file systems.
o /opt: Optional application software.
o /proc: Process information and system stats (virtual file system).
o /root: Root user’s home directory.
o /sbin: System binaries (used by system admin).
o /tmp: Temporary files.
o /usr: User programs, shared data, etc.
o /var: Variable data (logs, databases, etc.).
Importance of Root File System:
o OS Core Files: Sabhi system files jo booting, kernel, aur core system operations
ke liye zaroori hote hain, wo root file system mein stored hote hain.
o Boot Process: Jab system boot hota hai, kernel ko root file system se load kiya
jata hai. Agar root file system accessible nahi hota, to system boot nahi ho pata.
o Mounting: Jab system start hota hai, root file system sabse pehle mount hota
hai. Baad mein, doosre file systems ko mount kiya jata hai.
Example: Jab aap apne Linux system ko boot karte hain, root file system mount hota hai:
$ mount /dev/sda1 /
Yahaan /dev/sda1 partition ko root file system ke liye mount kiya ja raha hai.
2. Swap File System:
Definition:
o Swap file system ek special file system hai jo system ke RAM (Random Access
Memory) ki memory ko extend karta hai. Jab system ki physical RAM full ho jati
hai, to operating system ko additional memory chahiye hoti hai. Is situation
mein, system unused memory pages ko swap space (swap partition ya swap
file) mein transfer kar leta hai.
o Swap Space ek physical storage area hota hai jo temporary memory storage ke
roop mein kaam karta hai.
Types of Swap:
1. Swap Partition: Ek dedicated partition jo specifically swap space ke liye create
kiya jata hai.
2. Swap File: Ek regular file jo system ke file system mein create ki jati hai, aur
swap space ke liye use ki jati hai.
Working of Swap:
o Jab RAM mein memory ki kami hoti hai (e.g., heavy applications run kar rahe
hain ya system ki memory full ho gayi hai), Linux kernel swap space ka use karta
hai.
o Swap space ek slower storage area hota hai (usually hard disk ya SSD), isliye
system ko swap use karne par performance thodi slow ho sakti hai. Iska
purpose ye hota hai ki system ko crash hone se bachaya ja sake jab physical
memory available nahi hoti.
Importance of Swap Space:
o Memory Overflow: Jab system ka RAM full ho jata hai, swap space memory
overflow ko handle karta hai.
o Hibernation: Agar aapka system hibernate karta hai (system state ko disk pe
save karke power off karna), to swap space ka use current memory state ko
store karne ke liye hota hai.
Swap Space Size:
o General rule ke hisaab se, swap space ka size RAM ke size ke 1x se 2x tak hona
chahiye. Lekin, agar system ka heavy workload hai (e.g., servers), to zyada swap
space ki zaroorat ho sakti hai.
Example: Aap swap partition ko /etc/fstab file mein mount karte hain, jisse ye automatically
system startup ke time pe mount ho jata hai:
/dev/sda2 none swap sw 0 0
Agar aap swap file create karte hain, to aap command se swap file create kar sakte hain:
# Creating swap file (1GB size)
dd if=/dev/zero of=/swapfile bs=1M count=1024
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
Root aur Swap File System ka Difference:
Feature Root File System (/) Swap File System
Operating system aur core files ko Memory overflow handle karne ke liye
Purpose
store karta hai. temporary memory space.
Mounting Mount point none ya swap partition/file
Mount point / (root).
Point mein hota hai.
Ye ek regular file system hai (e.g., Ye ek special partition ya file hai jo swap
Type
ext4, xfs). ke liye use hoti hai.
System files, configurations, Memory pages ko temporarily store karta
Data Storage
libraries, binaries, etc. hai jab RAM full ho jati hai.
Speed Fast (access to core files needed for Slow (because swap is on disk, which is
Feature Root File System (/) Swap File System
system operations). slower than RAM).
Critical for system boot and Non-critical; swap is used only when RAM
Criticality
operation. is full.
Conclusion:
Root File System (/) Linux operating system ka core hai, jisme sabhi system files aur
directories stored hote hain.
Swap File System memory management ka ek part hai, jo system ko help karta hai jab
RAM full ho jata hai aur additional temporary space ki zaroorat hoti hai.
Dono file systems apne-apne specific tasks aur roles ko handle karte hain, taaki system
smoothly run ho sake.
FILE SYSTEM TYPES :
Linux mein kaafi different file system types available hote hain, har ek ka apna use case,
features aur performance characteristics hota hai. Linux ko flexibility provide karte hue, ye
multiple file system types ko support karta hai, jo different storage devices aur requirements
ke liye suitable hote hain. Chaliye, Linux file system types ko detail mein dekhte hain:
1. ext4 (Fourth Extended File System)
Description:
o Ye most common aur default file system hai Linux systems mein, aur isse zyada
tar users use karte hain.
o ext4 ext3 ka successor hai aur isme bohot improvements ki gayi hain, jaise
better performance, larger file sizes support, aur enhanced reliability.
Key Features:
o Journaling support (data integrity ke liye).
o Large file aur volume support (16 TiB file size, 1 EiB volume size).
o Extents ka concept (efficient block allocation).
o Improved performance aur reduced fragmentation.
o Backward compatibility with ext2/ext3.
Common Use Case:
o Personal computers, servers, and desktops jahan stability aur performance ki
zarurat ho.
2. ext3 (Third Extended File System)
Description:
o ext3 ek journaling file system hai aur ext2 ka upgraded version hai. ext3 ka
main advantage yeh hai ki isme journaling ka feature hai, jo file system ko
corruption se bachata hai.
Key Features:
o Journaling support (data consistency maintain karne ke liye).
o Moderate file size aur volume support (up to 2 TiB).
o Backward compatibility with ext2.
Common Use Case:
o Older systems jo ext4 ya ext2 use nahi kar rahe.
o Servers aur desktops jahan reliability important ho, lekin ext4 ka performance
required na ho.
4. XFS
Description:
o XFS ek high-performance, journaling file system hai jo large files aur high-
performance requirements ke liye design kiya gaya hai.
o Yeh file system especially large scale storage systems mein popular hai, jaise
enterprise servers aur high-performance computing.
Key Features:
o Journaling for data integrity.
o Supports large file sizes (up to 8 EiB) and large volumes.
o High scalability and performance for large data sets.
o Fast file system checks and recovery.
Common Use Case:
o High-performance applications, large databases, media servers.
o Enterprise-level servers jahan large-scale data management ho.
7. ReiserFS
Description:
o ReiserFS ek journaling file system hai jo primarily small files ke liye optimized
hai. Yeh file system high performance provide karta hai jab small files ko deal
karte hain.
Key Features:
o Journaling for data integrity.
o Optimized for small file handling and quick access.
o Supports up to 8 TiB file size and 16 TiB volume size.
Common Use Case:
o For servers or systems dealing with a large number of small files (e.g., email
servers, web servers).
Conclusion:
Linux mein file system types ka selection depend karta hai aapke use case par. Agar aapko
stability, performance aur compatibility chahiye, to ext4 sabse popular choice hai. Agar
aapko advanced features jaise snapshots, RAID support, aur high scalability chahiye, to Btrfs
ya ZFS consider kiya ja sakta hai.
ACESSING FILE SYSTEM :
Accessing file system ka matlab hai ki aap kisi system ke file system ko interact kar rahe
hote hain—yaani aap files aur directories ko dekh rahe hote hain, unmein changes kar rahe
hote hain, ya unhe manage kar rahe hote hain. File system ek organized structure hota hai
jisme files aur directories ko store kiya jata hai. Jab aap file system ko access karte hain, to
aapko permissions, file paths, aur file management tools ki zarurat hoti hai.
File System Access ka Basic Concept:
1. File System Structure:
o File system ek hierarchical structure hota hai jisme files aur directories stored
hoti hain.
o Aapko file system ko access karte waqt directory structure, file paths, aur
permissions ko samajhna padta hai.
2. File Paths:
o Absolute Path: File system mein kisi file ya directory ka full path, jo root
directory (/) se start hota hai. Example: /home/user/Documents/file.txt
o Relative Path: Current working directory se relative path. Example: Agar aap
/home/user/ directory mein hain, to Documents/file.txt ek relative path hai.
Conclusion:
Accessing file system ka matlab hai file system mein files aur directories ko view, modify,
copy, move, ya delete karna. Linux mein file system ko access karne ke liye aapko basic
commands (like ls, cd, cat, cp, mv, chmod) ka use karna hota hai. Agar aapko root privileges
ke saath access karna ho, to sudo ka use hota hai. Agar remote systems ke file systems ko
access karna ho, to aap SSH, SFTP, ya NFS ka use karte hain.
Accessing file system efficiently zaroori hai taaki aap system resources ko manage kar sakein
aur apni files ko safely store aur access kar sakein.
PROCESSES IN LINUX :
Processes Linux mein wo programs hote hain jo system ke under chal rahe hote hain. Jab
bhi aap koi command run karte hain, koi application open karte hain, ya koi background task
start karte hain, to wo process ke roop mein execute hota hai.
Linux mein har running program ya task ko ek unique process ID (PID) assign kiya jata hai,
aur ye process ek specific memory space mein apne instructions ko execute karta hai.
Linux Mein Process Ka Concept:
1. Process Definition:
o Ek process ek running program ka instance hai. Jab koi program ya command
execute hoti hai, to wo process ban jata hai.
o Process ek memory area allocate karta hai, jisme code, data, aur execution
state hoti hai.
2. Process State:
o Har process ka ek state hota hai, jo ye define karta hai ki process kis phase
mein hai. Typical states mein included hain:
Running: Process currently CPU pe execute ho raha hai.
Waiting: Process kisi resource (e.g., I/O operations, user input) ka wait
kar raha hai.
Sleeping: Process temporarily inactive hai (but still in memory).
Zombie: Process terminate ho chuka hai, but its information still present
hai system mein (it needs to be cleaned up).
Stopped: Process ko manually stop kar diya gaya hai.
3. Parent and Child Processes:
o Parent Process wo process hota hai jo kisi doosre process ko create karta hai.
o Child Process wo process hota hai jo ek parent process ke dwara create hota
hai.
o Forking ek process creation ka method hai, jisme parent process ek copy
banata hai apne aapki (child process).
o Example: Agar aap terminal pe ls command run karte hain, to bash shell usko
execute karega (parent process), aur ls command ka apna process (child
process) start hoga.
4. Process ID (PID):
o Har process ko ek unique Process ID (PID) diya jata hai. Ye identifier process ko
track karne ke liye use hota hai.
o The init process (PID 1) Linux system ka pehla process hota hai, aur baaki
processes iske under spawn hote hain.
5. Parent Process ID (PPID):
o Har process ka ek Parent Process ID (PPID) hota hai, jo us parent process ko
point karta hai jisse wo process spawn hua hai.
Process Components:
1. Process Control Block (PCB):
o Har process ka ek Process Control Block (PCB) hota hai, jo process ke baare
mein necessary information store karta hai. Ismein kuch important details hoti
hain:
PID (Process ID).
PPID (Parent Process ID).
Process state (e.g., running, waiting).
CPU registers (process ki current execution state).
Memory management information (kaunse memory blocks use ho rahe
hain).
Priority (process ki execution priority).
2. Memory Layout:
o Process ka ek apna allocated memory area hota hai, jisme typically yeh sections
hoti hain:
Text (Code) Segment: Ismein program ka actual code hota hai.
Data Segment: Program ke variables aur data structures stored hote
hain.
Heap: Dynamic memory allocation ke liye.
Stack: Function calls aur local variables ke liye.
BSS (Block Started by Symbol): Uninitialized global variables stored hote
hain.
Conclusion:
Kernel Mode mein processes ko system ke full control aur resources ka access hota
hai, aur wo directly hardware devices, memory management, aur device drivers se
interact karte hain.
User Mode mein processes ko restricted access milta hai, aur ye mostly user
applications ko run karne ke liye use hota hai. Agar inhe system resources access
karne ki zarurat ho, to wo kernel mode mein switch karte hain through system calls.
Ye separation system ke stability aur security ko ensure karte hain. Agar user mode
processes directly hardware ko access karte, to system ki security aur integrity compromise
ho sakti thi. Kernel mode mein only trusted and essential operations allowed hote hain.
Conclusion:
Starting a process Linux mein bahut simple hota hai: bas aapko command run karni
hoti hai, aur wo process start ho jata hai. Aap processes ko background mein bhi run
kar sakte hain.
Stopping a process ke liye aap Ctrl+C ka use kar sakte hain agar wo foreground mein
ho. Agar process ko manually terminate karna ho, to aap kill, killall, ya systemctl ka
use kar sakte hain.
INITIALIZATION PROCESS :
Process Initialization Linux mein ek important step hai jisme system boot hone ke baad
processes start hote hain. Ye initialization process system ke core components ko load
karne, resources ko allocate karne, aur system ko fully functional banane ke liye essential
hota hai.
Process Initialization in Linux
Linux mein process initialization kaafi structured hai, aur iska main goal system ko properly
start karna aur system-level processes ko launch karna hota hai. Ye steps follow karke Linux
ka boot process execute hota hai, aur uske baad processes run karte hain.
Conclusion:
Linux mein process initialization kaafi structured aur systematic hota hai. Sabse pehle
bootloader, phir kernel, aur uske baad init (ya systemd in modern systems) start hota hai.
Init system ko boot karne ke baad, system processes aur services ko launch karte hain. Iske
baad user login kar sakte hain aur system applications aur processes ko execute kar sakte
hain.
Ye process initialization ensure karta hai ki system properly boot ho aur user aur system
services efficiently work karein.
MECHANISM OF PROCESS PROCESS CREATION :
Process Creation Linux mein ek important mechanism hai jo naye processes ko system mein
start karne ke liye responsible hota hai. Jab koi naya process create hota hai, to system ko us
process ke liye resources allocate karne padte hain, jaise memory, CPU time, aur process
control block (PCB). Process creation ka mechanism Linux mein kaafi structured hota hai aur
isse processes ko efficiently manage kiya jata hai.
Process Creation Mechanism in Linux
Linux mein process creation ka mechanism primarily do important steps par based hota hai:
1. Forking (Child Process Creation)
2. Exec (Process Image Replacement)
1. Forking (Creating a Child Process)
fork() system call Linux mein process creation ka primary mechanism hai. Jab ek process
fork() system call execute karta hai, to wo apne identical child process ko create karta hai.
Forking Process:
Jab parent process fork() system call ko invoke karta hai, to ek child process create
hota hai. Parent aur child process initial state mein almost identical hote hain, lekin
unke process IDs (PIDs) different hote hain.
Parent Process ko apne resources aur memory ka access rehta hai, aur child process
ko naya address space aur resources allocate kiye jate hain.
fork() call ka return value parent aur child process ke liye alag hota hai:
o Parent process ko child process ka PID return hota hai.
o Child process ko 0 return hota hai, jo indicate karta hai ki yeh ek child process
hai.
Fork Example:
pid_t pid = fork();
if (pid == 0) {
// Child process
printf("This is the child process.\n");
} else if (pid > 0) {
// Parent process
printf("This is the parent process. Child PID is: %d\n", pid);
} else {
// Fork failed
printf("Fork failed.\n");
}
In this example:
Parent aur child processes dono apne respective statements print karenge.
Parent Process child process ka PID receive karega.
Conclusion:
Linux mein process creation ka mechanism primarily fork() aur exec() system calls par based
hota hai. Pehle parent process fork() call se child process create karta hai, aur phir child
process apne image ko replace karne ke liye exec() call karta hai. Is process mein Process
Control Block (PCB), parent-child relationships, aur signals bhi important roles play karte
hain. Ye steps system ko efficiently processes create karne aur manage karne mein madad
karte hain.
JOB CONTROL IN LINUX :
Job Control Linux mein ek important feature hai jo users ko processes ko manage karne aur
control karne ki ability deta hai. Job control ka use primarily terminal-based shell mein hota
hai, jisme aap apne running processes ko suspend, resume, foreground, ya background
mein shift kar sakte hain.
Job control ka main aim user ko ek better interface provide karna hai jisme wo apne
processes ko efficiently manage kar sake, without the need for complex system-level
commands.
Job Control in Linux
Job control Linux shells (jaise bash, zsh, sh, etc.) mein implemented hota hai aur ye aapko
running processes ko interactively manage karne ka power deta hai.
Important Notes:
at command ka use background jobs ke liye hota hai, lekin aap is command ka use kisi
specific time par kisi bhi job ko execute karne ke liye kar sakte hain.
at job ko execute hone ke baad automatically remove kar leta hai. Matlab, ek baar job
execute ho gaya, uske baad wo job queue se delete ho jata hai.
Agar aap chahte hain ki job ko repeatedly run karwana ho, to aap cron ka use kar
sakte hain.
Conclusion:
at command ka use aap scheduled jobs ko run karne ke liye kar sakte hain. Ye command job
control mein help karta hai, jisme aap kisi specific time par background mein jobs ko
execute karne ke liye schedule kar sakte hain. Aap atq se jobs dekh sakte hain, aur atrm se
jobs ko cancel bhi kar sakte hain. Iske through aap apni tasks ko automate kar sakte hain aur
process scheduling ko easily manage kar sakte hain.
BATCH :
Batch job control Linux mein batch command ka use karte hue batch jobs ko schedule
karna ek aur tarika hai jisme aap system ko schedule karte hain ki wo job ko system ke idle
hone par run kare. batch command similar to at command hai, lekin iska main difference ye
hai ki batch command jobs ko system load ke low hone par execute karne ke liye schedule
karti hai, na ki ek specific time par.
Batch Job Control in Linux using batch
1. What is batch Command?
The batch command in Linux schedules jobs to run when the system load is lower than a
threshold value. Matlab jab system ki load bahut high nahi hoti, to batch command
scheduled job ko execute karta hai. Ye especially useful hota hai jab aapko non-urgent jobs
ko run karna ho jab system idle ho.
2. Basic Syntax of batch Command:
batch [commands]
Jab aap batch command run karte hain, to aapko ek interactive shell milegi jahan aap
apne commands type karte hain.
batch command system load ko monitor karta hai aur jab system load acceptable level
pe aata hai, tab wo commands ko execute karna shuru karta hai.
Conclusion:
The batch command in Linux provides a way to schedule jobs that are executed when the
system load is lower. It's different from the at command because it doesn't require specifying
a time; instead, it waits for the system to be less busy. By using the batch command, you can
schedule non-urgent jobs to run during idle system periods, helping you manage system
resources effectively without overloading the system during peak usage times.
CRON & TIME :
Cron Linux mein ek time-based job scheduler hai, jo aapko tasks ko automatic way mein
schedule karne ki suvidha deta hai. Cron ka use regular, repetitive tasks ko schedule karne
ke liye kiya jata hai, jaise backup lene, reports generate karna, ya system maintenance jobs
ko automate karna.
Time-based jobs ko cron ke through schedule kiya jata hai, jahan aap specify karte hain ki
kaunsa job kab execute ho. Aap cron jobs ko time intervals, days, months, ya weekdays ke
hisaab se set kar sakte hain.
Cron Command and crontab
Linux mein cron daemon kaam karta hai jo system ke background mein chalta hai aur aapke
scheduled jobs ko execute karta hai. crontab command ka use cron jobs ko configure aur
manage karne ke liye hota hai.
Conclusion:
Cron job control mein time-based scheduling ka ek powerful tool hai jo aapko repetitive
tasks ko automate karne mein madad karta hai. crontab command ka use karke aap apne
tasks ko specific time intervals par schedule kar sakte hain, jaise daily, weekly, monthly, ya
kisi bhi specific date/time par. Cron jobs ko set karna bahut simple hai aur aap inhe easily
manage kar sakte hain, jo system administration aur maintenance tasks ko bahut asaan bana
deta hai.
Unit 4
SHELL PROGRAMING :
Shell programming Linux mein ek tarah ka scripting hai jisme aap shell (terminal) ko use
karke commands likhte hain aur unhe automate karte hain. Shell scripting mein aap
sequence of commands likhte hain jo ek program ki tarah execute hote hain. Ye
programming Linux ke command line environment mein hoti hai aur aapko repetitive tasks
ko automate karne, system maintenance ko simplify karne, aur complex tasks ko handle
karne mein madad deti hai.
Shell Programming ka Overview
Shell ek command-line interface (CLI) hota hai jo user aur operating system ke beech
interface provide karta hai. Aap shell scripting mein commands ko ek script file mein likhte
hain jo sequence mein execute hoti hain.
Shell programming ka use karke aap tasks ko automate kar sakte hain jaise file management,
backups, system monitoring, etc.
Shell Scripting Basics
1. What is a Shell?
o Shell ek program hota hai jo user ko system ke sath interact karne ka
environment provide karta hai. Iska kaam user ke input ko interpret karna aur
system ko instructions dena hota hai.
o Linux mein commonly used shells hain:
Bash (Bourne Again Shell): Sabse zyada popular shell hai.
Zsh (Z Shell): Yeh bhi kaafi popular hai, especially customization ke
liye.
Ksh (Korn Shell): Yeh bhi ek commonly used shell hai.
Tcsh: C shell ka advanced version hai.
2. Shell Scripting
o Shell scripting ek programming technique hai jisme aap shell ko use karke
sequence of commands likhte hain aur unhe automate karte hain.
o Scripting ka main purpose repetitive tasks ko automate karna, error-free
operations karna aur time save karna hota hai.
Conclusion:
Shell programming Linux mein ek powerful tool hai jo aapko system tasks ko automate
karne, processes ko manage karne, aur complex tasks ko efficiently perform karne mein
madad karta hai. Aap shell scripting ka use karke file management, system administration,
text manipulation, aur task automation ko easily handle kar sakte hain. Agar aap Linux ka
daily user hain ya system administrator hain, to shell scripting aapke kaam ko bahut asaan
aur efficient bana sakta hai.
VI EDITOR :
vi editor Linux mein ek powerful text editor hai jo command-line interface par kaam karta
hai. vi ka full form "Visual Interface" hai, aur yeh editor mainly text file editing,
configuration files ko modify karne, aur programming ke liye use hota hai. Yeh Linux (aur
Unix-based) systems mein built-in hota hai aur bahut popular hai, kyunki yeh lightweight,
fast, aur feature-rich hai.
vi Editor ke Features:
1. Command-line Based: vi ek command-line editor hai, jo terminal ke andar work
karta hai. Iska matlab hai ki aapko graphical user interface (GUI) ka use nahi karna
padta.
2. Modes: vi editor mein do main modes hote hain:
o Command Mode: Yeh mode by default hota hai jab aap vi editor open karte
hain. Is mode mein aap commands enter kar sakte hain, jaise text ko delete,
copy, paste, navigate, etc.
o Insert Mode: Is mode mein aap actual text type karte hain. Command mode se
insert mode mein switch karna padta hai.
3. Efficient Navigation: vi mein navigation ke liye keys kaafi powerful hote hain, jo ki
aapko file ke andar quickly navigate karne mein madad karte hain.
4. Search and Replace: vi mein aap text ko search kar sakte hain aur easily replace bhi
kar sakte hain.
5. Undo and Redo: vi editor mein undo aur redo karne ke options available hote hain.
6. Syntax Highlighting: Agar aap programming language mein code likh rahe hain, to vi
syntax highlighting feature ka support karta hai (ye feature vim mein zyada enhance
hota hai).
7. Customizability: vi ko customize karne ke liye configuration files (jaise .vimrc) ka
use hota hai. Aap apni preferences ke according vi ko set kar sakte hain.
Conclusion:
vi editor Linux mein ek powerful aur flexible text editor hai, jo terminal ke andar kaam karta
hai. Iska use text files ko efficiently edit karne, configuration files ko modify karne, aur
programming ke liye kiya jata hai. vi ke multiple modes aur commands ke through aap file
editing ko bahut efficiently kar sakte hain. Agar aap Linux ka use karte hain, to vi editor ka
use seekhna aapke liye kaafi useful hoga, kyunki yeh har Linux distribution mein available
hota hai.
SHELL VARIABLE :
Shell variables Linux mein aise variables hote hain jo shell session ke dauran data ko store
karte hain. Yeh variables shell scripts aur command-line sessions mein kaam aate hain aur
aapko dynamic values ko store karne, manipulate karne, aur unhe reuse karne mein madad
karte hain.
Linux shell mein generally do tarah ke variables hote hain:
1. Environment Variables
2. Shell Variables
1. Shell Variables
Shell variables woh variables hote hain jo shell session ke andar hi valid hote hain. Matlab
jab tak aapka current shell session chal raha hota hai, tab tak woh variables exist karte hain.
Jaise hi aap session close karenge, woh variables delete ho jayenge.
Example:
my_var="Hello, World!"
echo $my_var
Is example mein, my_var ek shell variable hai jisme "Hello, World!" store hai. Aap echo
$my_var command ke zariye uska value dekh sakte hain.
2. Environment Variables
Environment variables woh variables hote hain jo system-wide ya kisi specific session ke
liye available hote hain. Yeh variables aapke shell ke environment ko define karte hain, aur
agar aap kisi program ko execute karte hain, to woh programs bhi environment variables ka
access kar sakte hain.
Example:
$ echo $HOME
Is example mein, HOME ek environment variable hai jo user ke home directory ka path store
karta hai. Jab aap echo $HOME command run karte hain, to yeh aapke home directory ka
path print karega.
Shell Variables aur Environment Variables mein Differences
Shell Variables: Yeh variables sirf current shell session ke liye valid hote hain. Jaise
hi aap session close karenge, yeh variables disappear ho jayenge.
Environment Variables: Yeh variables system-wide hote hain aur agar aap kisi
program ko call karte hain, to woh programs bhi in variables ko access kar sakte hain.
Shell Variable ka Declaration aur Use
1. Variable Declaration Shell variable declare karte waqt, variable ka naam aur value
set ki jati hai. Aap directly = ke sign ke saath variable ko declare kar sakte hain. Note:
= ke baad koi space nahi hona chahiye.
Example:
my_variable="Linux is awesome"
2. Variable ka Access Variable ka value access karne ke liye $ sign ka use hota hai.
Example:
echo $my_variable
Isse my_variable ka value, jo ki "Linux is awesome", print hoga.
3. Variable ka Use in Shell Script Aap shell variables ko shell script mein use kar sakte
hain. For example:
4. #!/bin/bash
5. name="Alice"
6. echo "Hello, $name"
Is script ko run karne par output hoga:
Hello, Alice
Types of Shell Variables
1. User-defined Variables: Ye woh variables hote hain jo aap khud define karte hain.
Jaise my_var, name, count, etc.
Example:
count=10
echo "The count is $count"
2. Predefined (System) Variables: Linux shell mein kuch predefined variables hote
hain jo automatically available hote hain. Inko system-defined variables bhi kaha jata
hai. Example ke liye:
o $USER: Current logged-in user ka username.
o $HOME: Current user ka home directory.
o $PATH: Command search path. Yeh define karta hai ki system ko commands
kahan se search karni chahiye.
o $SHELL: Current shell ka path.
o $PWD: Current working directory.
o $0, $1, $2, ...: Command line arguments. $0 script ka naam hota hai, aur $1,
$2, ... arguments hote hain jo script ko run karte waqt diye jate hain.
Example:
echo $USER # Display current logged-in user
echo $HOME # Display home directory path
echo $SHELL # Display current shell
3. Special Shell Variables: Kuch special shell variables bhi hote hain jo shell scripting
mein use hote hain:
o $?: Last executed command ka exit status. Agar last command successful thi to
iska value 0 hota hai.
o $$: Current process ID (PID) of the shell.
o $!: Last background command ka PID.
Example:
echo $? # Shows the exit status of last command
echo $$ # Shows the current shell's process ID
Environment Variables ka Setting aur Exporting
1. Environment Variable Set Karna Aap shell variable ko environment variable mein
convert karne ke liye export command ka use kar sakte hain. Jab aap export use karte
hain, to variable shell environment mein available ho jata hai, aur koi bhi child process
usse access kar sakta hai.
Example:
export MY_VAR="Hello"
echo $MY_VAR
2. System-wide Environment Variables Agar aapko kisi variable ko permanently
environment variable banane ka zarurat ho, to aapko isse apne shell profile file mein
add karna padta hai. Jaise:
o Bash shell ke liye: /etc/bash.bashrc ya ~/.bashrc
o Zsh ke liye: ~/.zshrc
Example:
export MY_VAR="Hello, World!"
Isse jab bhi aap shell open karenge, MY_VAR environment variable available hoga.
Conclusion
Linux mein shell variables aur environment variables ka use bahut important hai. Shell
variables aapke current session ke liye hote hain, jabki environment variables system-wide
available hote hain aur kisi bhi child process ke liye accessible hote hain. Aap shell variables
ko declare kar sakte hain, unhe manipulate kar sakte hain, aur unka use shell scripting mein
bhi kar sakte hain. Agar aapko apne system ko customize karna hai ya automation karna hai,
to shell variables aapke liye bahut helpful hote hain.
I/0 IN SHELL :
I/O (Input/Output) in Shell Linux shell mein ek important concept hai jiska use data ko
programs ke beech transfer karne ke liye hota hai. Input aur output ka interaction user aur
program ke beech hota hai, aur shell mein yeh mainly standard input (stdin), standard
output (stdout), aur standard error (stderr) ke through manage hota hai.
I/O (Input/Output) Concepts in Shell
1. Standard Input (stdin):
o stdin ka matlab hota hai input jo ek program ko user ya kisi aur source se milta
hai.
o By default, shell input ko keyboard se read karta hai.
o Aap commands ya programs ko standard input ke through data de sakte hain.
Example:
o Jab aap cat command use karte hain, wo stdin se input leta hai.
cat
Is command ke baad jo bhi aap type karenge, wo cat ko input hoga.
2. Standard Output (stdout):
o stdout ka matlab hota hai output jo ek program ya command ke execution ke
baad user ko dikhayi jati hai.
o By default, shell ka output terminal (screen) par print hota hai.
Example:
o Agar aap echo command ka use karte hain, to output screen par print hota hai.
echo "Hello, World!"
Yeh command "Hello, World!" ko stdout par print karegi.
3. Standard Error (stderr):
o stderr ka matlab hai error messages jo program ko execute karte waqt generate
hoti hain.
o Yeh output errors ko handle karta hai aur standard output se alag hota hai.
Example:
o Agar aap koi invalid command run karte hain, to error message stderr ke
through print hota hai:
non_existent_command
Yeh command ek error dega jo stderr ke through show hoga.
I/O Redirection in Shell
I/O redirection ka use shell mein output ko ek file mein store karne, ya input ko kisi file se
lene ke liye hota hai. Iske liye >, >>, <, aur 2> operators ka use hota hai.
1. Redirecting Output (> and >>):
o > operator ka use standard output ko kisi file mein redirect karne ke liye kiya
jata hai. Yeh file ke content ko overwrite kar deta hai.
o >> operator ka use standard output ko kisi file mein append (add) karne ke liye
hota hai.
Example:
echo "This is a test" > output.txt # Overwrites content in output.txt
echo "Another line" >> output.txt # Appends to output.txt
2. Redirecting Input (<):
o < operator ka use kisi file ko standard input ke roop mein provide karne ke liye
hota hai.
Example:
sort < input.txt # Reads from input.txt and sorts the data
3. Redirecting Error Output (2>):
o 2> operator ka use error messages ko file mein redirect karne ke liye hota hai.
Example:
non_existent_command 2> error_log.txt # Redirects error to error_log.txt
4. Redirecting Both Output and Error (&> or 2>&1):
o Agar aapko standard output aur standard error dono ko ek hi file mein redirect
karna ho, to &> ya 2>&1 ka use karte hain.
Example:
command &> output_and_error.txt # Redirects both stdout and stderr to the file
Ya
command > output_and_error.txt 2>&1 # Redirects both stdout and stderr to the file
Pipes (|) in Shell
Pipes ka use ek command ka output dusri command ke input mein dene ke liye hota hai. Isse
aap ek sequence of commands execute kar sakte hain jisme ek command ka output directly
dusri command ko input ke roop mein diya jata hai.
Example:
ls -l | grep "txt"
Yeh command ls -l ka output grep ko pass karegi jo sirf "txt" ko filter karega.
Examples of I/O Operations in Shell
1. Using Standard Input:
o Aap cat command ke through kisi file ka content input ke roop mein de sakte
hain.
2. cat < input.txt # Takes input from input.txt
3. Using Standard Output:
o Aap echo command se output ko directly file mein redirect kar sakte hain:
4. echo "This is a new line" > output.txt # Redirects output to output.txt
5. Combining Output and Input:
o Aap cat ko input aur output dono ke liye use kar sakte hain:
6. cat < input.txt > output.txt # Takes input from input.txt and writes output to
output.txt
7. Using Pipes to Chain Commands:
o Aap pipes ka use multiple commands ko chain karne ke liye kar sakte hain:
8. cat input.txt | sort | uniq > output.txt # Sorts the contents of input.txt, removes
duplicates, and stores it in output.txt
Redirection with Background Processes
Aap background processes ko bhi input/output redirection ke saath use kar sakte hain. For
example, background mein run hone wale processes ka output redirect karna.
Example:
long_running_process > output.txt 2>&1 &
Isme process background mein run karega aur uska output aur error dono output.txt file mein
store ho jayenge.
Conclusion
I/O (Input/Output) shell mein bahut hi important concept hai, jisme aap commands ka input
provide karte hain aur unka output aur errors handle karte hain. Aap I/O redirection ke
through input ko files se le sakte hain aur output ko files mein store kar sakte hain. Pipes ka
use ek command ka output dusri command ke input mein dene ke liye hota hai. Yeh features
shell scripting ko powerful banate hain aur aapko complex tasks ko automate karne mein
madad karte hain.
COMPARISON OPERATORS :
Linux shell mein comparison operators ka use values ya variables ko compare karne ke
liye kiya jata hai. Yeh operators aapko conditional expressions mein help karte hain, jaise if,
while, ya test command ke andar. Yeh comparison operators do cheezon ko compare karte
hain — ya to strings, ya phir numbers.
1. String Comparison Operators
String comparison ka use tab hota hai jab aap do strings ya text ko compare karte hain. Isme
kuch common operators hain:
Operator Description
= String equality. Returns true if both strings are equal.
!= String inequality. Returns true if strings are not equal.
< Lexicographically less than. (ASCII order)
> Lexicographically greater than. (ASCII order)
-z True if the string is null (empty).
-n True if the string is not null (not empty).
Examples of String Comparison:
1. Equality (=):
2. str1="Hello"
3. str2="Hello"
4. if [ "$str1" = "$str2" ]; then
5. echo "Strings are equal"
6. else
7. echo "Strings are not equal"
8. fi
9. Inequality (!=):
10.str1="Hello"
11.str2="World"
12.if [ "$str1" != "$str2" ]; then
13. echo "Strings are not equal"
14.fi
15.Check if String is Empty (-z):
16.str=""
17.if [ -z "$str" ]; then
18. echo "String is empty"
19.fi
20.Check if String is Not Empty (-n):
21.str="Hello"
22.if [ -n "$str" ]; then
23. echo "String is not empty"
24.fi
4. Logical Operators
Logical operators ka use multiple conditions ko combine karne ke liye kiya jata hai.
Operator Description
&& AND operator. Executes the second command if the first command is true.
`
! NOT operator. Negates the result of the condition.
Examples of Logical Operators:
1. AND (&&):
2. num1=10
3. num2=20
4. if [ "$num1" -lt "$num2" ] && [ "$num1" -gt 5 ]; then
5. echo "$num1 is less than $num2 and greater than 5"
6. fi
7. OR (||):
8. num1=5
9. num2=3
10.if [ "$num1" -gt "$num2" ] || [ "$num1" -eq 5 ]; then
11. echo "$num1 is either greater than $num2 or equal to 5"
12.fi
13.NOT (!):
14.num1=10
15.if ! [ "$num1" -lt 5 ]; then
16. echo "$num1 is not less than 5"
17.fi
Conclusion
Linux mein comparison operators aapko different types of values (strings, numbers, files) ko
compare karne ki ability dete hain. String comparison, numeric comparison, aur file
comparison, sabhi alag-alag types ke operators ko use karte hain, jise aap conditional
expressions mein apply kar sakte hain. Logical operators ka use multiple conditions ko
combine karne ke liye hota hai. In operators ka use shell scripting mein kaafi important hai,
jisme aap decision-making aur automation tasks ko efficiently perform kar sakte hain
LOOPS IN LINUX:
Linux shell scripting mein loops ka use repetitive tasks ko automate karne ke liye hota hai.
Aap loops ka use ek ya zyada commands ko multiple times execute karne ke liye kar sakte
hain, jab tak ek condition true ho. Linux mein 3 main types ke loops hote hain:
1. for loop
2. while loop
3. until loop
Chaliye in teeno types ke loops ko detail mein samajhte hain:
1. for Loop
for loop ka use jab aapko ek predefined set of values ya range of numbers ke saath iteration
karna ho. Is loop ka use list ya range of values ko iterate karne ke liye hota hai.
Syntax:
for variable in value1 value2 value3 ...
do
# commands to be executed
done
Examples:
1. Loop over a list of values:
2. for color in red blue green
3. do
4. echo "The color is $color"
5. done
Is example mein, loop "red", "blue", aur "green" ke through iterate karega aur har iteration
mein color print karega.
6. Loop over a range of numbers (using seq):
7. for i in $(seq 1 5)
8. do
9. echo "Number: $i"
10.done
Yeh loop numbers 1 se 5 tak print karega.
11.Loop with a specific range:
12.for i in {1..5}
13.do
14. echo "Iteration number: $i"
15.done
16.Loop over files in a directory:
17.for file in /path/to/directory/*
18.do
19. echo "File: $file"
20.done
2. while Loop
while loop ka use tab hota hai jab aapko ek condition ko check karna ho aur jab tak woh
condition true ho, tab tak commands ko repeat karte rehna ho.
Syntax:
while [ condition ]
do
# commands to be executed
done
Examples:
1. Loop until a condition is met:
2. count=1
3. while [ $count -le 5 ]
4. do
5. echo "Count is $count"
6. ((count++)) # increment the count by 1
7. done
8. Infinite loop (use carefully):
9. while true
10.do
11. echo "This will run forever"
12.done
Agar aapko infinite loop chahiye, to while true ka use kar sakte hain.
13.Loop until a file exists:
14.while [ ! -f /tmp/myfile.txt ]
15.do
16. echo "File does not exist yet, checking again..."
17. sleep 1
18.done
19.echo "File exists now!"
3. until Loop
until loop ka behavior while loop ke opposite hota hai. Yeh loop tab tak commands ko
execute karta hai jab tak condition false hai. Jaise hi condition true ho jati hai, loop terminate
ho jata hai.
Syntax:
until [ condition ]
do
# commands to be executed
done
Examples:
1. Loop until condition is true:
2. count=1
3. until [ $count -gt 5 ]
4. do
5. echo "Count is $count"
6. ((count++)) # increment the count by 1
7. done
8. Infinite loop with until:
9. until false
10.do
11. echo "This will also run forever"
12.done
5. Nested Loops
Aap loops ko ek dusre ke andar bhi nest kar sakte hain (nested loops). Yeh tab kaam aata hai
jab aapko multiple conditions ko handle karna ho ya multi-dimensional data ko process
karna ho.
Example of Nested Loops:
for i in {1..3}
do
for j in {A..C}
do
echo "i=$i, j=$j"
done
done
Is example mein, outer loop 1 se 3 tak iterate karega, aur inner loop A se C tak iterate
karega, jo total 9 combinations banayenge.
Conclusion:
Linux shell mein loops aapko repetitive tasks ko automate karne ki flexibility dete hain. Aap
for, while, aur until loops ka use karke different conditions ke basis par commands ko repeat
kar sakte hain. Loop control statements jaise break aur continue ka use loop ki execution
ko control karne ke liye kiya jata hai. Yeh sab features aapko powerful shell scripts likhne
mein madad karte hain jo aapke day-to-day tasks ko automate kar sakte hain.
CONDITIONAL CONTROL STRUCTURE :
In Linux shell scripting, conditional control structures are used to make decisions based on
the outcome of a test or condition. These structures allow you to execute different
commands or blocks of code depending on whether a condition is true or false.
There are several key conditional control structures in Linux shell scripting:
1. if statement
2. if-else statement
3. if-elif-else statement
4. case statement
5. test command (used with [ or [[)
Let’s break them down one by one:
1. if Statement
The if statement is used to test a condition, and if that condition evaluates to true, it executes
a block of code.
Syntax:
if [ condition ]
then
# commands to be executed if the condition is true
fi
Example:
num=10
if [ $num -gt 5 ]; then
echo "Number is greater than 5"
fi
In this example, since $num is 10, which is greater than 5, the condition is true, and the
message is printed.
2. if-else Statement
The if-else statement allows you to execute one block of code if the condition is true, and
another block of code if the condition is false.
Syntax:
if [ condition ]
then
# commands to be executed if the condition is true
else
# commands to be executed if the condition is false
fi
Example:
num=3
if [ $num -gt 5 ]; then
echo "Number is greater than 5"
else
echo "Number is less than or equal to 5"
fi
Here, since $num is 3, which is less than or equal to 5, the else block will execute.
3. if-elif-else Statement
The if-elif-else structure is used when you have multiple conditions to check. It allows you
to test multiple conditions sequentially.
Syntax:
if [ condition1 ]
then
# commands to be executed if condition1 is true
elif [ condition2 ]
then
# commands to be executed if condition2 is true
else
# commands to be executed if none of the conditions are true
fi
Example:
num=7
if [ $num -gt 10 ]; then
echo "Number is greater than 10"
elif [ $num -gt 5 ]; then
echo "Number is greater than 5 but less than or equal to 10"
else
echo "Number is 5 or less"
fi
In this case, since $num is 7, the second condition ($num -gt 5) will be true, and the second
block will execute.
4. case Statement
The case statement is a way to test a value against several possible values. It is particularly
useful when you have multiple values for one variable and want to handle them differently.
Syntax:
case $variable in
pattern1)
# commands to be executed if the variable matches pattern1
;;
pattern2)
# commands to be executed if the variable matches pattern2
;;
*)
# commands to be executed if no pattern matches
;;
esac
Example:
day="Monday"
case $day in
"Monday")
echo "Start of the week"
;;
"Friday")
echo "End of the week"
;;
"Saturday" | "Sunday")
echo "Weekend"
;;
*)
echo "Midweek"
;;
esac
Here, the variable $day is "Monday", so the first block will execute and print "Start of the
week".
Conclusion:
Conditional control structures in Linux shell scripting are essential for making decisions in
your scripts. The if, if-else, if-elif-else, and case statements let you control the flow of
execution based on conditions. You can also use the test command (or [ ] / [[ ]]) to evaluate
conditions such as string comparison, numeric comparison, and file existence checks.
These conditional structures allow you to write more dynamic and flexible scripts that can
perform different actions based on the input, environment, or other conditions.
COMMAND LINUX ARGUMENT :
Command line arguments in Linux allow you to pass additional information to a script or
command when running it from the terminal. These arguments can be used to customize the
behavior of a script or command based on input provided by the user at runtime.
How Command Line Arguments Work:
In Linux, when you execute a script or command, you can provide additional arguments after
the command itself. These arguments are typically accessed in the script using special
variables.
Common Special Variables:
1. $0 – The name of the script or command being executed.
2. $1, $2, ..., $n – These represent the positional parameters (arguments) passed to the
script. $1 is the first argument, $2 is the second, and so on.
3. $# – The total number of arguments passed to the script.
4. $@ – A list of all the arguments passed to the script, quoted individually.
5. $* – A single string of all arguments passed to the script.
6. $? – The exit status of the last command executed.
7. $$ – The process ID (PID) of the script's current shell.
Using $@ vs $*:
Both $@ and $* represent all the arguments passed to the script, but there is a subtle
difference:
$@: Treats each argument as a separate quoted entity. This is useful when you have
multiple arguments with spaces.
$*: Combines all arguments into a single string, where arguments are not quoted
individually.
Example:
#!/bin/bash
echo "Using \$@ : $@"
echo "Using \$* : $*"
Run the script with arguments:
./example.sh "Argument 1" "Argument 2" "Argument 3"
Output:
Using $@ : Argument 1 Argument 2 Argument 3
Using $* : Argument 1 Argument 2 Argument 3
With $@, each argument is quoted separately.
With $*, all arguments are combined into one string.
To see the difference more clearly, you can use quotes around $@ and $*:
echo "Using \$@ : \"$@\""
echo "Using \$* : \"$*\""
This will show the difference in how arguments with spaces are treated.
if [ $# -eq 0 ]; then
echo "No arguments provided"
else
echo "You provided $# arguments"
fi
If you run the script without any arguments:
./example.sh
Output:
No arguments provided
If you run the script with arguments:
./example.sh one two three
Output:
You provided 3 arguments
Conclusion:
Command line arguments in Linux are a powerful way to pass input to your scripts. By using
variables like $0, $1, $2, $@, and $#, you can handle dynamic input and customize the
behavior of your scripts. You can also manipulate and process these arguments with
commands like shift or iterate over them with loops. Command line arguments are essential
for making scripts more flexible and interactive.
COMMAND POSITIONAL PARAMETER :
In Linux shell scripting, positional parameters refer to the arguments passed to a script or
function when it is executed. These parameters are represented by special variables that are
used to access the individual arguments in the order they were provided. Positional
parameters are an essential part of shell scripting, as they allow you to pass and handle input
dynamically.
Positional Parameters:
1. $0 – The name of the script or command being executed.
2. $1, $2, ..., $n – These represent the positional parameters (arguments) passed to the
script. $1 is the first argument, $2 is the second, and so on.
3. $# – The total number of positional parameters (arguments) passed to the script.
4. $@ – A list of all the arguments passed to the script, quoted individually.
5. $* – A single string of all arguments passed to the script, with no quotes around them.
6. $? – The exit status of the last command executed.
7. $$ – The process ID (PID) of the script's current shell.
Using Positional Parameters in a Shell Script:
Example 1: Accessing Positional Parameters
Let's create a simple shell script to access and display the command line arguments passed to
it.
1. Create a script called pos_params.sh:
#!/bin/bash
Using $@ vs $*
Both $@ and $* represent all the arguments passed to the script, but they handle quoting
differently.
$@: This treats each argument as a separate entity, which means each argument is
quoted separately.
$*: This combines all arguments into a single string, without individual quotes.
Example: Difference Between $@ and $*
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Error: You need to provide at least two arguments."
exit 1
fi
Conclusion
In Linux shell scripting, positional parameters are a powerful way to handle command-line
input. By using special variables like $0, $1, $2, $@, $#, and $*, you can access and
manipulate the arguments passed to your script. You can also use commands like shift to
modify the argument list or loop through arguments using for. These features allow you to
create flexible and dynamic shell scripts that respond to user input at runtime.
SUBPROGRAM :
Subprograms in Linux (and more generally in shell scripting) refer to smaller, self-
contained blocks of code that can be executed independently within a larger script or
program. These subprograms are often used to perform specific tasks, and they help break
down a complex script into more manageable parts. In Linux shell scripting, subprograms
can be implemented as functions or external commands.
Let’s dive deeper into what subprograms are in Linux and how you can use them in shell
scripting:
1. Functions as Subprograms in Shell Scripts
In Linux shell scripting, a function is a way to define a subprogram that can be called with
parameters and return a value (or perform an action). Functions allow you to reuse code
without repeating it.
Defining a Function:
A function is defined with the following syntax:
function_name() {
# Commands or code to execute
}
Or you can also define it using the function keyword:
function function_name {
# Commands or code to execute
}
Calling a Function:
You can call the function simply by its name:
function_name
Example: Simple Function in Shell Script
#!/bin/bash
# Define a function
greet() {
echo "Hello, $1!"
}
Unit 2
EXPRESSIONS :
In Linux shell scripting, expressions are used to perform operations and evaluate conditions.
These expressions can be used in various contexts such as conditional statements (if, while),
loops, and arithmetic operations. Linux supports several types of expressions, including
arithmetic expressions, logical expressions, string expressions, and file test expressions.
Below is an overview of these different types of expressions and how they are used in Linux
shell scripting.
1. Arithmetic Expressions
Arithmetic expressions allow you to perform mathematical operations like addition,
subtraction, multiplication, division, etc. In Linux shell scripting, these expressions are
typically used with the (( )) syntax or the let command.
Using (( )) for Arithmetic
#!/bin/bash
a=5
b=3
a=5
b=3
str1="Hello"
str2="World"
str="Hello, Linux"
str=""
if [ -z "$str" ]; then
echo "String is empty"
else
echo "String is not empty"
fi
Output:
String is empty
-z checks if the string length is zero (empty).
-n checks if the string has a non-zero length.
4. String Comparison (<, >, ==, !=):
#!/bin/bash
str1="Apple"
str2="Banana"
a=5
b=3
a=5
b=10
a=5
b=10
if [ $a -lt $b ]; then
echo "$a is less than $b"
fi
Output:
5 is less than 10
Conclusion
In Linux shell scripting, expressions are used to evaluate conditions, perform mathematical
calculations, and manipulate strings or files. You can use:
Arithmetic expressions to perform calculations ($(( ))).
String expressions to compare or manipulate strings.
Logical expressions to combine multiple conditions with logical operators (&&, ||).
File test expressions to check the properties of files and directories.
Integer comparison expressions to compare numerical values.
These expressions are essential tools for building dynamic and flexible shell scripts that can
handle complex logic and tasks efficiently.
FILERS :
In Linux, filters are commands or programs that process and manipulate data in a pipeline.
They read data from standard input (stdin), perform operations on the data, and then output
the result to standard output (stdout). Filters are typically used in conjunction with pipes (|)
to pass the output of one command as the input to another command, allowing you to chain
commands together and perform complex tasks.
Key Features of Filters in Linux:
Process data streams: Filters are designed to process streams of data (e.g., text).
Operate on stdin and stdout: Filters take input from stdin (standard input) and output
to stdout (standard output).
Can be combined: Filters can be chained together using pipes (|) to form powerful
data processing pipelines.
Common Linux Filters
Here are some of the most commonly used filters in Linux:
Conclusion
In Linux, filters are powerful tools for processing and transforming data in text streams.
Some of the most commonly used filters are:
grep (search for patterns),
awk (text processing),
sed (stream editing),
sort (sorting),
cut (extract columns),
head and tail (viewing file contents),
tee (capturing output),
tr (character translation),
wc (word/line/character counting).
By using filters in combination with each other, you can perform complex data processing
tasks efficiently.
AWK :
AWK ek powerful text-processing tool hai jo Linux (aur dusre Unix-like systems) mein
commonly use hota hai. Ye primarily pattern scanning aur processing ke liye design kiya
gaya hai. AWK ka use karke hum text files ko efficiently manipulate kar sakte hain, jaise ki
log files, CSV files, aur kisi bhi structured data ko process karna.
AWK ka naam Alfred Aho, Peter Weinberger, aur Brian Kernighan ke naam par pada
hai, jo is tool ke creators the. AWK ek programming language bhi hai jo mainly text
processing ke liye banayi gayi thi.
AWK ki Key Features:
Pattern Matching: AWK aapko patterns (regular expressions) ke through text ko
match karne ki facility deta hai.
Field-based Processing: AWK har line ko fields mein todta hai. Ye fields $1, $2,
$3, ... ke roop mein refer kiye jate hain, jahan $1 pehla field hai, $2 dusra field, aur
aise hi.
Built-in Variables: AWK mein kuch built-in variables hote hain jaise NR (Number of
Records), NF (Number of Fields), jo processing ko bahut asaan bana dete hain.
Control Flow: AWK mein aap conditionals (if, else), loops (for, while), aur functions
ka use kar sakte hain, jo isse ek full-fledged programming language banata hai.
Powerful Output Formatting: AWK mein aap output ko format karne ke liye printf
ka use kar sakte hain.
AWK ka Basic Syntax:
AWK ka basic syntax kuch is tarah hota hai:
awk 'pattern { action }' input-file
pattern: Ye woh condition hai jo AWK match karta hai, jaise koi regular expression.
action: Jab AWK pattern ko match kar leta hai, tab ye action perform karta hai. Agar
action diya na ho, toh AWK by default puri line ko print kar deta hai.
input-file: Ye input file hoti hai jise AWK process karta hai.
AWK ke Example:
1. Line-by-Line Processing
AWK default taur pe har line ko process karta hai. Isme $1, $2, $3, etc., fields ko represent
karte hain, aur $0 puri line ko represent karta hai.
# Example: File ki first aur third column print karo
awk '{ print $1, $3 }' filename.txt
Yahaan $1 aur $3 respective columns ko print karenge.
2. Pattern Matching
Agar aapko kisi specific pattern ko match karna ho, toh AWK mein aap easily regular
expressions ka use kar sakte hain.
# Example: "error" word ko search karo aur print karo
awk '/error/ { print $0 }' filename.txt
Yahaan /error/ ek pattern hai jo file mein har us line ko match karega jisme "error" word
hoga. $0 se puri line print hogi.
3. Field Delimiters
AWK ka default field separator space aur tab hota hai. Lekin aap kisi aur delimiter ka bhi
use kar sakte hain, jaise comma , for CSV files.
# Example: CSV file mein comma `,` ko delimiter use karo
awk -F ',' '{ print $1, $2 }' filename.csv
Yahaan -F ',' ka matlab hai ki AWK ko comma ko field separator ke roop mein consider
karna chahiye.
4. Performing Calculations
AWK mein aap arithmetic operations bhi kar sakte hain. Ye kaafi useful hota hai jab aapko
kisi column ke values ko manipulate ya calculate karna ho.
# Example: 2nd aur 3rd column ko add karo
awk '{ print $2 + $3 }' filename.txt
Yahaan $2 + $3 ka matlab hai 2nd aur 3rd columns ko add karna aur result print karna.
5. Built-in Variables
AWK mein kuch built-in variables hote hain jo aapko data process karne mein madad karte
hain. Jaise:
$0: Puri line ko represent karta hai.
$1, $2, ...: Individual fields ko represent karte hain.
NR: Current record/line number.
NF: Current line mein fields ki total number.
# Example: NR aur NF ka use karna
awk '{ print "Line:", NR, "Fields:", NF }' filename.txt
Isme NR se line number aur NF se current line mein fields ki total count print hogi.
6. Using BEGIN and END Blocks
AWK mein aap BEGIN aur END blocks ka use kar sakte hain jo input file ke processing se
pehle aur baad mein kuch kaam karte hain.
# Example: BEGIN block to set field separator, END block for summary
awk 'BEGIN { FS="," } { print $1, $2 } END { print "File processed!" }' filename.csv
BEGIN block ka use hum field separator (FS) set karne ke liye karte hain.
END block mein aap koi summary ya conclusion print kar sakte hain.
Conclusion:
AWK ek bahut hi powerful aur flexible tool hai jo text processing aur data manipulation ke
liye use hota hai. Agar aapko file ki specific columns ko extract karna, kisi data ko process
karna, ya patterns ko match karna ho, toh AWK ek excellent tool hai. Iske through aap
complex data transformation tasks ko easily perform kar sakte hain.
AWK ko seekhna Linux mein text processing aur data handling ke kaafi important skills
mein se ek hai.
Commands in Linux: -
Commands refers to one-line statements that operate on the supplied operands to perform
some action. Each command is supported with certain options that add extra features to the
command. These options enable the user in driving the command to carry out the desired
action. The options are mostly prefixed with hyphen (-) and more than one option can be
used in a command.
• Structure of Commands: -
Command-name [-options] [arguments]
Here, options are generally in form of a character prefixed by a hyphen (-), which is used
for a particular feature of the command and the argument refers to the content or data to
which a command is to be applied. An argument can be a file, directory, terminal or device
etc.
• Types of commands: -
1. Internal commands: - The shell has a number of built-in commands that are
known as internal commands. Some of these, such as cd and echo, do not generate
a process, and are directly executed by the shell. These commands are built into the
shell and do not exist as separate files.
For all the shell built-in commands, execution of the same is fast in the sense that the shell
doesn’t have to search the given path for them in the PATH variable, and also no process
needs to be spawned for their execution.
Example: - pwd, help, cd, alias, logout, type, echo etc.
Type “echo $PATH” to have all path values. PATH is a system variable which
stores a list of
directories that the shell searches to locate a .
command
Similarly, “echo $SHELL” is used to get the
default shell used.
2. External commands: - External commands are utilities and programs such
as cat and ls. These commands exist in the form of individual files and are
distributed in different directories. The commonly used user commands are
placed in the /bin directory, and the commands that are usually used only by
system administrators are placed in the /sbin directory.
When an external command has to be executed, the shell looks for its path given in the
PATH variable, and also a new process has to be spawned and the command gets
executed. Example: - cat, login, date, cal, mkdir etc.
PIPES IN LINUX :
Pipes Linux mein ek bahut hi important aur powerful concept hai jo command-line
tools ko ek dusre ke saath combine karne mein madad karta hai. Pipes ka use ek
command ka output directly dusre command ko input dene ke liye hota hai, bina kisi
intermediate file ke. Isse aap ek complex task ko multiple simpler commands mein
divide kar sakte ho aur unhe ek sequence mein execute kar sakte ho.
Pipes (|) in Linux:
Pipes ko | symbol ke saath represent kiya jata hai. Jab aap | ka use karte hain, ek
command ka output directly dusri command ke input mein chala jata hai.
Key Points:
Data Flow: Pipe ek data stream ka flow create karta hai, jisme pehli command ka
output directly dusri command ko pass hota hai.
No Intermediate File: Pipe ka use karke aap bina kisi temporary file ko create kiye
commands ko link kar sakte hain.
Chaining Commands: Aap multiple commands ko pipe karke ek complex task
complete kar sakte hain.
Pipes ka Basic Syntax:
command1 | command2 | command3 | ...
command1: Pehli command jo output generate karti hai.
command2, command3, ...: Dusri aur aage ki commands jo pehli command ka output
as input accept karti hain.
Pipes ka Example:
1. Basic Pipe Example:
ls | grep "txt"
ls: Ye current directory ke files list karta hai.
Pipe (|): ls ka output directly grep command ko input ke roop mein diya jata hai.
grep "txt": Ye un files ko filter karega jisme "txt" word ho.
Output:
file1.txt
file2.txt
Is example mein:
ls command se directory ke files list honge.
grep "txt" un files ko filter karega jisme "txt" ho.
2. Multiple Pipes Example:
cat file.txt | grep "error" | sort | uniq
Yahaan:
1. cat file.txt: File ka content print karta hai.
2. Pipe (|): cat ka output grep "error" ko input ke roop mein diya jata hai.
3. grep "error": Ye file se un lines ko filter karega jo "error" word contain karte hain.
4. Pipe (|): grep ka output sort ko input ban jayega.
5. sort: Ye filtered lines ko sort karega.
6. Pipe (|): sort ka output uniq ko diya jayega.
7. uniq: Ye sorted output mein se duplicate lines ko remove karega.
Output:
error: failed to load module
error: missing file
3. Using ps with Pipe Example:
ps aux | grep "root"
Yahaan:
1. ps aux: Ye system par running processes ki details print karta hai.
2. Pipe (|): ps aux ka output grep "root" ko input ke roop mein diya jata hai.
3. grep "root": Ye un processes ko filter karega jo "root" se related hain.
Output:
root 1 0.1 0.0 16892 2084 ? Ss 12:30 0:02 /usr/lib/systemd/systemd --
switched-root --system --deserialize 22
root 22 0.0 0.0 19464 1892 ? Ss 12:30 0:00 /usr/lib/systemd/systemd-
journald
4. Using ls and wc (Word Count) with Pipe Example:
ls -l | wc -l
Yahaan:
1. ls -l: Ye long listing format mein files show karega.
2. Pipe (|): ls -l ka output wc -l ko input diya jayega.
3. wc -l: Ye line count karega, matlab ki directory mein kitne items hain.
Output:
15
Conclusion:
Pipes (|) Linux mein ek powerful mechanism hai jo ek command ka output directly
dusri command ko input bana leta hai, bina kisi intermediate file ke.
Efficiency ko improve karte hue aap multiple commands ko chain kar sakte ho aur ek
complex task ko simple steps mein break kar sakte ho.
Pipes ko filters ke saath use karke aap data ko modify, format, aur analyze kar sakte
ho.
Pipes ko samajhna aur efficiently use karna Linux ka ek important skill hai jo aapke
command-line experience ko kaafi improve kar sakta hai!
Linux mein bahut saari commands hoti hain jo system ko manage karne, files ko
handle karne, aur system administration tasks ko perform karne ke liye use hoti hain.
Main aapko Linux ke kuch basic aur commonly used commands ke baare mein
bataunga.
The important LINUX commands are grouped according to their functions and explained
as follows: -
• File-oriented commands
• General-Purpose commands
• File-oriented commands
• Directory-oriented commands
• Communication-oriented commands
• Process-oriented commands
Ye list Linux ke basic aur commonly used commands ka overview deti hai. Linux
mein bahut saari advanced aur specific commands bhi hoti hain jo system
administration, networking, aur debugging ke liye use hoti hain. Aap in commands ko
apni needs ke hisaab se explore kar sakte hain!
COMMON COMMANDS :
Linux ke basic commands un commands ko kaha jata hai jo daily use mein kaafi aati
hain, jaise file management, directory navigation, system information, aur process
management. Ye commands beginner level pe kaafi useful hoti hain aur aapko Linux
terminal pe kaam karne mein madad deti hain.
Basic Linux Commands:
1. Directory Navigation Commands
1. pwd: Print Working Directory
o Ye command aapko current directory ka path batata hai.
o Example:
o pwd
2. ls: List Files and Directories
o Ye command current directory mein files aur directories list karta hai.
o Example:
o ls
3. cd: Change Directory
o Ye command aapko ek directory se dusri directory mein navigate karne ke liye
use hota hai.
o Example:
o cd /home/user/Documents
o cd .. se aap ek level up ja sakte hain.
4. cd ~: Go to the home directory
o Ye command aapko directly home directory mein le jata hai.
o Example:
o cd ~
5. cd -: Go to the previous directory
o Ye command aapko last visited directory pe le jata hai.
o Example:
o cd -
2. File Management Commands
1. touch: Create an empty file or update timestamp
o Ye command ek empty file create karta hai ya existing file ka timestamp update
karta hai.
o Example:
o touch newfile.txt
2. cp: Copy files or directories
o Ye command file ko copy karta hai.
o Example:
o cp source.txt destination.txt
3. mv: Move or rename files or directories
o Ye command file ko move ya rename karta hai.
o Example:
o mv oldfile.txt newfile.txt
4. rm: Remove files or directories
o Ye command file ko delete karta hai.
o Example:
o rm file.txt
5. rm -r: Remove a directory and its contents
o Ye command directory ko delete karta hai, uske andar ki saari files aur
subdirectories ke saath.
o Example:
o rm -r foldername
6. mkdir: Create a new directory
o Ye command nayi directory create karta hai.
o Example:
o mkdir newfolder
7. rmdir: Remove an empty directory
o Ye command ek empty directory ko delete karta hai.
o Example:
o rmdir emptyfolder
8. rename: Rename files or directories
o Ye command file ya directory ka naam change karta hai.
o Example:
o rename oldname.txt newname.txt
3. File Viewing and Editing Commands
1. cat: Concatenate and display file content
o Ye command file ka content print karta hai.
o Example:
o cat file.txt
2. more: View file content one page at a time
o Ye command file ka content ek screen pe display karta hai.
o Example:
o more file.txt
3. less: View file content with navigation options
o Ye command file ka content display karta hai aur aap easily scroll kar sakte
hain.
o Example:
o less file.txt
4. nano: Text editor for creating or editing files
o Ye command text file ko edit karne ke liye ek simple text editor open karta hai.
o Example:
o nano file.txt
5. vim or vi: Advanced text editor for creating or editing files
o Ye command advanced text editing ke liye use hota hai.
o Example:
o vim file.txt
4. File Permission Commands
1. chmod: Change file permissions
o Ye command file ya directory ki permissions ko change karta hai.
o Example:
o chmod 755 file.txt
2. chown: Change file owner
o Ye command file ya directory ka owner change karta hai.
o Example:
o chown user:user file.txt
3. chgrp: Change group ownership
o Ye command file ya directory ka group ownership change karta hai.
o Example:
o chgrp groupname file.txt
5. System Information Commands
1. uname: Display system information
o Ye command system ki basic information dikhata hai.
o Example:
o uname -a
2. top: Display real-time system resource usage (CPU, memory)
o Ye command system ka resource usage (jaise CPU, memory) show karta hai.
o Example:
o top
3. uptime: Show how long the system has been running
o Ye command system ke uptime ko show karta hai.
o Example:
o uptime
4. free: Display memory usage
o Ye command system ki memory usage dikhata hai.
o Example:
o free -h
5. df: Show disk space usage
o Ye command disk ki space usage dikhata hai.
o Example:
o df -h
6. du: Display disk usage of files and directories
o Ye command file aur directories ka size dikhata hai.
o Example:
o du -sh /path/to/directory
7. whoami: Display the current logged-in user
o Ye command current user ka naam dikhata hai.
o Example:
o whoami
8. who: Display who is logged into the system
o Ye command system par kis-kis user ka login hai, wo dikhata hai.
o Example:
o who
6. Process Management Commands
1. ps: Show current running processes
o Ye command current running processes ko dikhata hai.
o Example:
o ps aux
2. top: Display running processes and system usage
o Ye command system ke real-time resource usage aur running processes ko show
karta hai.
o Example:
o top
3. kill: Terminate a process by its PID
o Ye command kisi process ko terminate karne ke liye use hota hai.
o Example:
o kill 1234 # Where 1234 is the Process ID (PID)
4. killall: Kill processes by name
o Ye command kisi process ko uske name se terminate karta hai.
o Example:
o killall firefox
7. Search Commands
1. grep: Search for a pattern in files
o Ye command file mein kisi pattern ko search karta hai.
o Example:
o grep "pattern" filename.txt
2. find: Search for files in a directory hierarchy
o Ye command specified directory mein file search karta hai.
o Example:
o find /home/user/ -name "*.txt"
8. Miscellaneous Commands
1. man: Display the manual or help file of a command
o Ye command kisi bhi command ka manual page dikhata hai.
o Example:
o man ls
2. clear: Clear the terminal screen
o Ye command terminal ko clean kar deta hai.
o Example:
o clear
3. exit: Exit from the terminal session
o Ye command terminal ko exit karta hai.
o Example:
o exit
Ye kuch basic aur commonly used Linux commands hain jo aapko daily tasks mein
madad karengi. In commands ka use karke aap apne system ko efficiently manage kar
sakte hain.