Linux Fundamentals Part 1
Welcome to the first part of the “Linux Fundamentals” room series ka swagat hai. Shayad aap abhi Windows ya Mac machine use kar rahe hain β dono ka visual design aur kaam karne ka tareeka alag hota hai. Jaise Windows, iOS aur macOS hote hain, waise hi Linux bhi ek operating system hai β aur duniya ke sabse popular OS me se ek hai. Ye smart cars, Android devices, supercomputers, home appliances, enterprise servers, aur bahut kuch ko power deta hai.
Is room me hum Linux ka thoda history cover karenge aur phir aapka safar shuru hoga ek Linux-wizard banne ka! Yahaan aap:
Apne pehle commands run karenge ek interactive Linux machine me, browser ke through
Kuch essential commands seekhenge jo file system se interact karne ke kaam aate hain
Dekhenge kaise files search karte hain aur shell operators ka use kaise hota hai
Research Question:
What year was the first release of a Linux operating system?
Answer:Β 1991
Linux ka pehla version 1991 me release hua tha, jab Linus Torvalds ne ek open-source operating system kernel develop kiya tha jo later “Linux” ke naam se famous hua.
Linux kaha use hota hai?
Yeh kehna galat nahi hoga ki Linux thoda intimidating lag sakta hai, especially jab aap usse Windows jaise Operating Systems (OSs) se compare karte ho. Dono ke apne-apne advantages aur disadvantages hote hain.
Example ke liye, Linux kaafi lightweight hota hai β aur aapko jaan kar hairani hogi ki ho sakta hai aap rozana kisi na kisi form me Linux use kar rahe ho! Linux power deta hai:
Websites jo aap visit karte ho
Cars ke entertainment ya control panels
Point of Sale (PoS) systems jaise ki shops me checkout tills ya registers
Critical infrastructure jaise traffic lights controllers ya industrial sensors
Linux ke Flavours (Types)
“Linux” naam actually ek umbrella term hai jo kai Operating Systems ke liye use hota hai jo UNIX (ek aur OS) pe based hote hain. Linux open-source hone ki wajah se, iske bahut saare versions ya variants banaye gaye hain β alag-alag needs ke hisaab se customize kiye ja sakte hain.
Example ke liye, Ubuntu aur Debian kaafi common Linux distributions hain, kyunki ye kaafi extensible hote hain. Matlab, aap Ubuntu ko ek server ki tarah (jaise websites ya web apps ke liye), ya ek full desktop system ki tarah bhi chala sakte ho.
Is series me hum Ubuntu use karne wale hain.
Note: Ubuntu Server sirf 512MB RAM wale system pe bhi chal sakta hai!
Jaise Windows ke alag versions hote hain (7, 8, 10), waise hi Linux ke bhi kaafi saare versions ya distributions hote hain.
Answer the question below:
Research: Pehla Linux Operating System kis saal release hua tha?
π Answer: 1991
Is room me ek Ubuntu Linux machine hai jisse aap directly apne browser me interact kar sakte ho, jab aap is room ka material follow kar rahe ho.Lekin shuru karne ke liye, bas neeche diye gaye green “Start Machine” button par click karo.
Start Machine
Jaise hi machine deploy hoti hai, room ke top me ek card show hoga:Is card me aapko machine ke baare me saari information milegi β jaise:
- IP address
- Expiry timer
- Aur machine manage karne ke buttons
Yaad rahe: Jab aap is room ke saath kaam kar chuke ho, to machine ko “Terminate” karna na bhoolen. Iske baare me aur information aapko tutorial room me mil jayegi.Abhi ke liye, “Start Machine” par click karein β aur apne browser me hi apni khud ki Linux machine ke saath interact karna shuru karein, room ke steps follow karte hue.
Jaise ki hum pehle discuss kar chuke hain, Ubuntu jaise OS ka ek bada selling point yeh hai ki yeh kaafi lightweight hote hain. Lekin iske kuch disadvantages bhi hote hain β jaise, aksar inme GUI (Graphical User Interface) nahi hoti, yaani koi desktop environment nahi hota jise hum mouse se operate kar saken (jab tak woh install na kiya gaya ho).
Aise systems ke saath interact karne ka main tareeka hota hai “Terminal” ka use karna.
Terminal kya hota hai?
Terminal ek text-based interface hota hai β matlab sirf likh kar hi system ko commands dete hain. Shuru me yeh thoda intimidating lag sakta hai, lekin jab aap kuch basic commands seekh lete ho, toh yeh kaafi easy lagne lagta hai.
Terminal ka example:
tryhackme@linux1:~$ enter commands here
Humein kuch basic tasks karne aane chahiye β jaise:
Files tak navigate karna
Unka content dekhna
Nayi files banana
Iske liye jo commands use hoti hain, wo simple hoti hain (jab aap unhe jaan jaate ho π)
Letβs start with two basic commands:
| Command | Description |
|---|---|
echo | Koi bhi text output karne ke liye |
whoami | Yeh check karne ke liye ki hum kis user ke roop me login hain |
echo ka example:
tryhackme@linux1:~$ echo Hello
Hello
tryhackme@linux1:~$ echo "Hello Friend!"
Hello Friend!
Agar sirf ek word print karna ho, toh quotes ki zarurat nahi hoti.
Example:echo HelloAgar multiple words ya space ho, toh double quotes lagane chahiye.
Example:echo "Hello Friend!"
whoami ka use:
tryhackme@linux1:~$ whoami
Yeh command batata hai ki aap currently kis user ke roop me logged in ho.
β Answer the questions below:
If we wanted to output the text “TryHackMe”, what would our command be?
Answer:echo TryHackMe
What is the username of who you’re logged in as on your deployed Linux machine?
β οΈ Iska answer aapko apni Linux machine mewhoamicommand run karke dekhna hoga.
Example command:whoami
Output me jo username aaye, wahi yahan likhna hai.
(Jaise example metryhackmeaata hai, toh answer hoga:tryhackme)
Ab tak humne sirf “echo” aur “whoami” commands ke baare me hi padha hai. Lekin agar hum actually system ke sath kaam karna chahte hain β jaise ki filesystem me navigate karna, files ko padhna ya likhna, toh hume aur commands seekhni hongi.Is task me, hum aise hi kuch commands seekhne wale hain. Jaise pichle task me kiya tha, waise hi is baar bhi commands ek table me diye jayenge, aur unke examples bhi.
π Filesystem ke sath interact karna
Jaise maine pehle bataya tha, bina desktop environment ke machine me navigate karna bahut important hai. Agar hum kisi jagah ja hi nahi sakte, toh login ka kya fayda?
π§ Commands Table
| Command | Full Form |
|---|---|
ls | listing (files/folders dikhane ke liye) |
cd | change directory (folder change karne ke liye) |
cat | concatenate (file ka content dekhne ke liye) |
pwd | print working directory (current location dekhne ke liye) |
π ls β Current Directory ke Files/Folders dikhana
Kisi bhi file ka content dekhne se pehle hume yeh toh pata hona chahiye ki kya cheezein maujood hain. Iske liye ls command ka use hota hai.
tryhackme@linux1:~$ ls
'Important Files' 'My Documents' Notes Pictures
Upar ke output se pata chalta hai ki yeh folders available hain:
- Important Files
- My Documents
- Notes
- Pictures
π§ Pro Tip: Kisi specific folder ka content dekhna ho bina usme jaaye, toh aise likho:
ls Pictures
π cd β Directory Change Karna
Agar aapko kisi folder ke andar jaana hai, toh use cd command se ja sakte ho.
Example:
cd Pictures
ls
Output:
dog_picture1.jpg dog_picture2.jpg dog_picture3.jpg dog_picture4.jpg
Yahan 4 dog pictures hain!
π cat β File ka Content Output Karna
File ke existence ke baare me pata hona useful hai, lekin jab tak uska content na dekhein, tab tak kaam adhura hai.cat ka full form hota hai concatenate, lekin yeh mainly files ka content dikhane ke kaam aata hai.Example:
tryhackme@linux1:~/Documents$ ls
todo.txt
tryhackme@linux1:~/Documents$ cat todo.txt
Here's something important for me to do later!
π§ Pro Tip: Agar aap kisi file ka content dekhna chahte ho bina us folder me jaaye, toh aise likho:
cat /home/ubuntu/Documents/todo.txt
π pwd β Current Location ka Full Path dekhna
Kabhi kabhi hum bhool jaate hain ki hum exactly system me kis folder me hain. Isliye pwd ka use hota hai.Example:
tryhackme@linux1:~/Documents$ pwd
/home/ubuntu/Documents
Iska matlab: Documents folder system me yahan store hai: /home/ubuntu/DocumentsAb future me agar hum kahin aur chale jayein, toh simply:
cd /home/ubuntu/Documents
karke wapas aa sakte hain.
β Answer the Questions Below:
- On the Linux machine that you deploy, how many folders are there?
(Hint: Uselsin the home directory)
Example answer:Β4
- Which directory contains a file?
(Hint: Uselscommand on each folder to check which one has a file)
Example answer:ΒDocuments
- What is the contents of this file?
(Hint: Usecaton the file inside that folder)
Example answer:ΒHere's something
- What is the path (current working directory) after using
cdto go to that fileβs folder?
(Hint: Usepwdaftercdinto the folder)
Example answer:Β/home/ubuntu/Documents
Let me know if you want to fill these with your actual machine output!
Jab tak abhi tak lag nahi raha ho, Linux ka ek bada hi useful feature yeh hai ki aap iske saath bahut efficient ho sakte ho. Lekin yeh tabhi possible hai jab aap isko achhe se jaante ho. Jaise-jaise aap Ubuntu jaise operating systems ke saath interact karte jaoge, waise-waise kuch basic commands aapko yaad ho jaayengi bina soche-samjhe β jaise muscle memory.
Ek zabardast tareeka yeh dikhane ka ki aap kitne efficient ho sakte ho, woh hai kuch commands ka use karke jaldi se poore system mein files dhoondhna β bina baar-baar cd aur ls use kiye.
Iske liye hum find command ka use karte hain jo hamare liye yeh kaam easy bana deta hai.
Find ka use
find command bahut hi useful hai. Aap isko simple ya complex tareeke se use kar sakte ho β depend karta hai aapko kya dhoondhna hai.
Sabse pehle basic se start karte hain.
Neeche ek example diya gaya hai jisme hum current directory ke andar kya-kya folders hain woh ls command se dekhte hain:
tryhackme@linux1:~$ ls
Desktop Documents Pictures folder1
Ab, har folder ke andar aur folders ho sakte hain. Agar humein koi specific file dhoondhni hai, toh manually har folder ke andar dekhna time waste karega.
Isiliye hum find command ka use karte hain.
Example 1: Jab file ka naam pata hai
Maan lo humein pata hai ki file ka naam passwords.txt hai lekin location nahi pata. Toh hum yeh command use karenge:
find -name passwords.txt
Output kuch aisa aayega:
./folder1/passwords.txt
Matlab file folder1 ke andar hai.
Example 2: Jab sirf extension pata hai (jaise .txt)
Agar humein pata nahi ki file ka exact naam kya hai, lekin pata hai ki file .txt extension wali hai, toh hum wildcard use karte hain:
find -name *.txt
Output:
./folder1/passwords.txt
./Documents/todo.txt
Toh find ne dono .txt files ko dhoondh liya β ek folder1 mein aur doosri Documents mein.
Simple tha, hai na?
Grep ka use
Ab baat karte hain ek aur useful command ki β grep.
grep se hum file ke content ke andar specific words ya values dhoondh sakte hain.
Maan lo humein web server ka access.log file mila jisme 244 lines hain:
wc -l access.log
244 access.log
Agar hum poori file ko cat se read karein toh bahut time lagega. Maan lo humein sirf ek IP address ke related info dekhni hai β jaise “81.143.211.90”
Toh hum use karenge:
grep "81.143.211.90" access.log
Aur output milega:
81.143.211.90 - - [25/Mar/2021:11:17 +0000] "GET / HTTP/1.1" 200 417 "-" "Mozilla/5.0 ..."
Matlab grep ne poori file me dhoondh ke sirf wahi line dikhayi jisme IP address tha.
Final Task:
Question: access.log file (jo /home/tryhackme/ directory mein hai) ko grep se search karo aur flag dhoondo jo THM se start hota hai.
Command kuch aisa hoga:
grep "THM" /home/tryhackme/access.log
Jo bhi result milega, usme THM{...} jaisa kuch hoga β wahi flag hoga.
Linux operators ek zabardast tareeka hain Linux ke saath kaam karne ki knowledge ko aur strong banane ka. Kuch important operators hote hain jo yaad rakhna zaroori hai. Hum yahan pe basic operators ko chhoti-chhoti parts mein todh ke samjhayenge.
Ek overview ke taur pe, hum in operators ko cover karenge:
| Symbol / Operator | Description |
|---|---|
& | Is operator ka use karke aap commands ko terminal ke background mein chala sakte ho. |
&& | Iska use multiple commands ko ek hi line mein combine karke chalane ke liye hota hai. |
> | Ye ek redirector hota hai β iska matlab hai ki kisi command ka output (jaise cat command ka) kisi aur jagah bhej sakte ho. |
>> | Ye bhi wahi kaam karta hai jaise > operator, lekin output ko file ke end mein add karta hai β overwrite nahi karta. |
Chalo inhe thoda detail mein samajhte hain.
Operator “&“
Ye operator humein allow karta hai commands ko background mein chalane ke liye. For example, agar hum ek bada file copy kar rahe hain, to obviously isme time lagega, aur tab tak terminal busy ho jayega.
Lekin agar hum & operator ka use karein, to ye command background mein chalegi β jisse hum aur kaam kar sakte hain jab tak file copy ho rahi hoti hai.
Operator “&&“
Ye operator shayad pehle wale & jaisa lagta ho, lekin iska kaam alag hai. && se aap multiple commands ek line mein chala sakte ho, jaise:
command1 && command2
Iska matlab hai command2 tabhi chalegi jab command1 successfully complete ho jaaye.
Operator “>“
Ye ek output redirector hai. Iska matlab ye hai ki aap kisi command ka output kisi file ya jagah pe redirect kar sakte ho.
Ek simple example: agar hum echo howdy run karein to terminal mein “howdy” print hoga β lekin agar hum chahte hain ki ye ek file mein save ho jaaye, to hum > ka use kar sakte hain.
Example:
Agar hum ek file banani hai jiska naam ho "welcome" aur usmein likhna hai "hey", to hum likhenge:
echo hey > welcome
Aur agar hum cat welcome karein to output milega:
hey
Note: Agar “welcome” file pehle se exist karti hai, to purani content overwrite ho jaayegi.
Operator “>>“
Ye bhi ek output redirector hai, lekin thoda different hai. Jab aap >> ka use karte ho, to ye existing file ke andar ka content overwrite nahi karta, balki append karta hai β yaani file ke end mein naya data add karta hai.
Example:
Agar “welcome” file ke andar pehle se "hey" likha hai, aur aap likhte ho:
echo hello >> welcome
To cat welcome ka output hoga:
hey
hello
Questions
Agar humein koi command background mein run karni ho, to kaunsa operator use karenge?
Answer:&Agar main ek file jiska naam “passwords” hai, uske content ko “password123” se replace karna chahta hoon, to command kya hogi?
Answer:echo password123 > passwordsAb agar main chahta hoon ki “tryhackme” bhi ussi file mein add ho jaaye bina “password123” ko hataye, to command kya hogi?
Answer:echo tryhackme >> passwords
Nice work! Tum iss stage tak aa gaye ho β great job! Humne kaafi kuch cover kiya hai tumhari pehli Linux interaction ke liye. Yeh sab cheezein kaafi essential hain aur tum jab bhi kisi Linux machine ke saath kaam karoge, baar-baar inka use hoga.
Umeed hai yeh room tumhare liye zyada overwhelming nahi tha β jaise maine pehle bhi bola tha, yeh sab tumhe jaldi familiar lagne lagega kyunki tum inhe baar-baar use karoge.
Quick Recap β Ab tak humne kya-kya seekha:
β
Samjha ki Linux aaj ke time mein itna popular kyun hai
β
Apni pehli Linux machine ke saath interact kiya
β
Kuch basic aur fundamental commands run ki
β
File system ke around navigate karna seekha β aur kaise find aur grep jaisi commands se data dhundhna easy ho sakta hai
β
Shell operators ke baare mein jaana jo commands ko aur powerful bana dete hain
Thoda time lo, aur iss room mein maze se practice karo. Jab thoda aur comfortable feel karne lago, tab Linux Fundamentals Part 2 pe move kar jaana.