Skip to main content

Bash Basics: Linux වල සරල කාර්යයන් ස්වයංක්‍රීය කිරීම | Bash Automation Basics In Sinhala

 

Bash Basics: Linux වල සරල කාර්යයන් ස්වයංක්‍රීය කිරීම


මේ වගේ වැඩ ටිකක් කරන්න වුනොත් ඔයා කොහොමද ඒක කරන්නේ  ?

ඔබට අවශ්‍යයි  කියලා හිතන්න:

  • Files 500ක් rename කරන්න
  • දිනපතා folders backup කරන්න
  • පැයකට වරක් server health check කරන්න
  • සතිපතා data reports process කරන්න

ඔයාට මේවා manually කරන්න පුළුවන්. click කරන්න, type කරන්න, නැවත නැවත කරන්න හෝ ඔබට සරල Bash script එකක් ලියලා ඔබේ computer එකට එය handle කරන්න දෙන්න පුළුවන් ඔබ වඩාත් interesting දෙයක් මත focus වෙන අතරතුර.

Bash (Bourne Again Shell) Linux හි built-in scripting language එක. මේක complicated programming එකක් නෙවෙයි. මේක ඔබ දැනටමත් දන්න commands, file එකක ලියලා automatically execute කරනවා. Students, developers, system administrators, සහ repetitive tasks වලින් මහන්සි වෙච්ච හැමෝටම, Bash productivity superpower එකක්.

Bash කියන්නේ මොකක්ද?

Bash කියන්නේ Linux වල command-line interpreter එක. ඔබ commands type කරන shell එක, ඒත් එය scripting language එකක් කියන්නත් පුළුවන් , ඒ Bash Scripting ,commands automated workflows එකක් බවට combine කරන්න ඔබට ඉඩ දෙනවා.

මේක මෙහෙම හිතන්න:

  • Manually commands type කිරීම = එකින් එක පිඟන් සෝදන්න
  • Bash script එකක් ලියන්න = පිඟන් සෝදන යන්ත්‍රයක් තියෙනවා වගේ 

Bash Automation,

  • එකම task එක කීපවරක් නැවත නැවත කරනවා
  • Schedule එකකට commands run කරනවා
  • Bulk එකේ files process කරනවා
  • ඉක්මනින් environments set up කරනවා
  • human error  අඩු කරනවා


Junior developer කෙනෙක් සෑම සඳුදාවකම පැය 2ක් manually project files organize කරන්න ගත කළා. Bash ඉගෙන ගත්තට පස්සේ, ඇය එකම task එක තත්පර 3කින් කරන පේළි 10ක script එකක් ලිව්වා. ඇයට සෑම සතියකම ඒ පැය 2 ආපහු ලැබුණා .

First Bash Script: Hello, Automation

සරලම script එක සාදමු:

#!/bin/bash
echo "Hello, automation!"

මේක hello.sh විදියට save කරන්න, executable කරන්න, සහ run කරන්න:

chmod +x hello.sh
./hello.sh

Output: Hello, automation!

දැනගත යුතු ප්‍රධාන Bash Basics

1. Variables – තොරතුරු ගබඩා කිරීම

name="Linux"
echo "I am learning $name"

Variables ඔබට reuse කරන්න ඕන data hold කරනවා. = sign එක වටේ spaces තියන්නේ නෑ!

2. Loops – ක්‍රියා නැවත නැවත කිරීම

Files 100ක් rename කරන්න ඕනද? Loop එකක් use කරන්න:

for file in *.txt; do
  mv "$file" "${file%.txt}_backup.txt"
done

මේක extension එකට කලින් _backup add කරමින් සියලුම .txt files rename කරනවා. Manually? ඒ renames 100ක්. Bash සමඟ එක command එකක්.

3. Conditions – තීරණ ගැනීම

if [ -f "report.txt" ]; then
  echo "Report exists"
else
  echo "Report not found"
fi

ඔබේ script එකට දැන් තනියමම  respond කරන්න පුළුවන්.

4. User Input කියවීම

echo "Enter your name:"
read username
echo "Welcome, $username!"

Real-World Automation උදාහරණ

උදාහරණය 1: දෛනික Backup Script

#!/bin/bash
backup_dir="/home/user/backups"
mkdir -p "$backup_dir"
cp -r /home/user/Documents "$backup_dir/Documents_$(date +%Y%m%d)"
echo "Backup completed!"

Cron (Linux හි task scheduler) use කරලා මේක දිනපතා run කරන්න, ඔබ backups ගැන කවදාවත් worry වෙන්න ඕන නෑ.

උදාහරණය 2: System Health Check

#!/bin/bash
echo "=== System Health Report ==="
echo "Disk Usage:"
df -h | grep /dev/sda1
echo "Memory Usage:"
free -h
echo "Top 5 Processes:"
ps aux --sort=-%mem | head -6

health_check.sh විදියට save කරන්න. දැන් system status check කිරීම commands පහකට වඩා එක command එකක්.

උදාහරණය 3: Bulk File Renaming

#!/bin/bash
for file in *.jpg; do
  mv "$file" "photo_$(date +%s)_$file"
done

සියලුම .jpg files වලට ක්ෂණිකව timestamps add කරනවා. Photos organize කරන්න perfect.

Bash Skills Career-Critical වන්නේ ඇයි?

DevOps සහ Cloud Engineering

Infrastructure automation දැඩි ලෙස Bash මත රඳා පවතිනවා. Servers deploy කිරීම, containers manage කිරීම, environments configure කිරීම Bash scripts heavy lifting එකක්  කරනවා.

Cybersecurity

Security professionals automate කරනවා:

  • Log analysis
  • Vulnerability scanning
  • Incident response workflows

Real case: Ethical hacker කෙනෙක් Bash සමඟ reconnaissance tasks automate කළා, පැය ගණන් manual වැඩ විනාඩි දක්වා කපා හැරියා.

Data Science සහ AI

Researchers Bash use කරනවා:

  • Datasets preprocess කරන්න
  • Model training pipelines automate කරන්න
  • Experiments schedule කරන්න

System Administration

Admins servers සිය ගණනක් manage කරනවා. Manual configuration? Impossible. Bash scripts consistency සහ speed ensure කරනවා.

නවීන tech stacks—Docker, Kubernetes, CI/CD pipelines, cloud platforms—හැමදේම Bash automation integrate කරනවා.

වඩාත් Smart ව වැඩ කරන්න

කාලය ඉතිරි කරන්න – Repetitive tasks automate කරන්න
වැරදි අඩු කරන්න – Scripts වලට typos කරන්න බෑ
පහසුවෙන් scale කරන්න – එක script එකක්, අසීමිත භාවිතයන්
ඉක්මනින් ඉගෙන ගන්න – Automation තේරුම් ගැනීම Linux දැනුම ගැඹුරු කරනවා
Career value වැඩි කරන්න – Automation ඉහළම demand කරන skill එකක්

💡 ඔබ දැනගෙන සිටියාද?

  • NASA Mars rovers වල system checks automate කරන්න Bash scripts use කරනවා
  • #!/bin/bash line එක (shebang) Linux වලට කියනවා භාවිතා කරන්න ඕන interpreter එක කුමක්ද කියලා
  • ඔබට cron jobs use කරලා automatically run වෙන්න Bash scripts schedule කරන්න පුළුවන්—එක්තරා set කරන්න, සදහටම අමතක කරන්න

⚡ Pro ඉඟි

ඉඟිය 1: Real files වලට කලින් dummy data මත scripts test කරන්න. Script එකක rm භයානක විය හැකියි!

ඉඟිය 2: Scripts ආරම්භයේ set -e use කරන්න—කිසියම් command එකක් fail උනොත් එය execution එක නවත්වනවා, cascading errors වළක්වනවා.

ඉඟිය 3: ඔබේ code එකට # සමඟ comments දාන්න. අනාගත ඔබ (හෝ teammates) ඔබට ස්තූති වන්දනා කරයි.

# මේක වැදගත් files backup කරනවා
cp -r /data /backup 

Free Resources For Level Up  

  • Linux Journey – Bash scripting tutorials
  • ShellCheck.net – ඔබේ scripts errors සඳහා validate කරනවා
  • ExplainShell.com – ඔබ paste කරන ඕනෑම Bash command එකක් explain කරනවා
  • FreeCodeCamp – Bash scripting crash course (YouTube)
  • TryHackMe – Linux automation labs

Bash scripting කියන්නේ programmer කෙනෙක් වෙන එක ගැන නෙවෙයි, ඔබේ කාලය ආපහු claim කරන එක ගැනයි . ඔබේ computer එකට කියන එක ගැන: "මේ කම්මැලි දේ මට වෙනුවෙන් කරන්න, සදහටම."

හොඳම කොටස? ඔබ දැනටමත් commands දන්නවා. ඔබ just ඒවා වඩාත් smart ව organize කරනවා.

කුඩා script එකකින් ආරම්භ කරන්න. කරදරකාරී task එකක් automate කරන්න. ඉන්පස්සේ තවත් එකක්. ඔබ දැනගන්න කලින්, ඔබ තමයි "දේවල් ඉක්මන් කරන්නේ කොහොමද කියලා දන්න" කෙනා.


Remember that,සෑම expert කෙනෙක්ම වරක් beginner කෙනෙක් 

Comments

Popular posts from this blog

Linux ඇත්තටම වැඩ කරන්නේ කොහොමද? | How Actualy Linux Works in Sinhala

Linux ඇත්තටම වැඩ කරන්නේ කොහොමද (Filesystem, Kernel සහ Processes විස්තරාත්මකව) Linux තේරුම් ගැනීම වැදගත් වන්නේ ඇයි? Linux හැම තැනම තියෙනවා , servers වල, smartphones වල, cloud platforms වල, supercomputers වල, space missions වල පවා. ඒත් බොහෝ beginners ලාට Linux දැනෙන්නේ අමුතු commands සහ අමුතු folders පිරුණු  "Black box" එකක්  විදියට. Linux ඇතුළතින් ඇත්තටම වැඩ කරන ආකාරය තේරුම් ගැනීම , commands type කරන විදිය විතරක් නෙවෙයි හැමදේම වෙනස් කරනවා. ඒක Linux එක ඔබ use කරන දෙයකින් ඔබ control කරන දෙයකට පරිවර්තනය කරනවා. students, developers, cybersecurity ඉගෙන ගන්න බොහෝ  දෙනෙකුට , සහ අනාගත engineers ලාට මේ දැනුම දිගු කාලීන වාසියක්. Linux එක නගරයක් වගේ හිතන්න: Kernel එක නගර පාලනයයි —සම්පත් කළමනාකරණය කරලා නීති බලාත්මක කරනවා. Filesystem එක නගරයේ සැලැස්මයි —හැමදේම store කරලා organize කරලා තියෙන ආකාරය. Processes මිනිස්සු සහ වාහන —ක්‍රියාකාරීව වැඩ කරන programs. සෑම කොටසකටම පැහැදිලි කාර්යභාරයක් තියෙනවා, එකට ඒවා system එක stable, fast සහ secure කරනවා. 1. Linux Filesystem:  Li...

Linux Network Troubleshooting In Sinhala

  Linux Network Troubleshooting: ping, traceroute, සහ ss  Internet ගැටලු Fix කරන, Server ගැටලු Diagnose කරන, සහ IT Departments දිනපතා use කරන ප්‍රධාන Commands හැඳින්වීම... "Server එක down." "මට database එකට connect වෙන්න බෑ." "Website එක load වෙන්නේ නෑ." සෑම IT professional කෙනෙක්, system administrator කෙනෙක්, සහ developer කෙනෙක්ම මේ වචන නිතරම අහනවා. ඒත් ඔවුන්  panic වෙන්නේ නෑ ඔවුන් එය troubleshoot කරනවා. Linux network troubleshooting magic එකක් නෙවෙයි. එය ඔබේ computer එක සහ ලෝකයේ සෙසු කොටස අතර ඇත්තටම මොකද වෙන්නේ කියලා හරියටම reveal කරන ශක්තිමත්, built-in tools භාවිතා කරන ක්‍රමානුකූල ක්‍රියාවලියක්. ඔබ networking ඉගෙන ගන්න student කෙනෙක් වුණත්, applications debug කරන developer කෙනෙක් වුණත්, හෝ infrastructure manage කරන system administrator කෙනෙක් වුණත්  ping , traceroute , සහ ss master කිරීමෙන් network problems අභිරහස් වලින් එහාට ගිය විසඳිය හැකි ප්‍රහේලිකා බවට පරිවර්තනය වෙනවා. Network සන්නිවේදනය වැඩ කරන ආකාරය Troubleshooting වලට කලින්, මේ සරල සත්...