Linux Terminal, Bash Shell & Standard Streams (I/O & Pipes)
පිටුව 02: Linux Terminal, Bash Shell සහ Standard Streams (stdin, stdout, stderr, pipes)
Command line එක ක්රියාත්මක වන ආකාරය, Standard Streams (stdin 0, stdout 1, stderr 2), Output Redirection (> සහ >>) සහ Pipes (|) භාවිතය සරලව ඉගෙන ගනිමු.
Lab 02 of 20 · Shell & Streams · 5 hands-on activities · bilingual (English + සිංහල)
පිටුව 02: Linux Terminal, Bash Shell සහ Standard Streams (stdin, stdout, stderr, pipes)
Command line එක ක්රියාත්මක වන ආකාරය, Standard Streams (stdin 0, stdout 1, stderr 2), Output Redirection (> සහ >>) සහ Pipes (|) භාවිතය සරලව ඉගෙන ගනිමු.
💡 සරල සිංහලෙන්: stdin, stdout, stderr සහ Pipes (|) ජල නල පද්ධතියක් වගේ
වතුර බට 3ක උපමාව:
- stdin (බටය 0): Command එක ඇතුළට වතුර (දත්ත) එන බටය.
- stdout (බටය 1): Command එකේ සාර්ථක ප්රතිඵල එළියට එන පිරිසිදු වතුර බටය.
- stderr (බටය 2): මොකක් හරි Error එකක් ආවොත් එළියට එන අපිරිසිදු වතුර බටය. මේ දෙක වෙන් කරලා තියෙන්නේ පිරිසිදු දත්ත අපිරිසිදු නොවෙන්නයි.
- Pipe (|): එක Command එකක එළියට එන බටය (stdout), ඊළඟ Command එකේ ඇතුල් වෙන බටයට (stdin) කෙලින්ම සවි කරන Connector එකයි Pipe (|) කියන්නේ! උදාහරණයකට
ps aux | grep nginxකියන්නේ: සියලුම Process ලයිස්තුව අරගෙන, ඒකෙන් nginx තියෙන පේළි විතරක් පෙරලා ගන්න කියන එකයි.
Architectural Foundation & Systems Diagram
In DevOps and SRE, you rarely have a graphical user interface (GUI). You control servers via the Bash Shell. Every command in Linux communicates through standard streams represented by integer file descriptors:
-
📥 stdin (File Descriptor 0) — Standard Input. Data fed into a command, typically from your keyboard or piped from another program's output.
-
📤 stdout (File Descriptor 1) — Standard Output. Normal output produced by a successful command. By default, it prints to your terminal screen.
-
⚠️ stderr (File Descriptor 2) — Standard Error. Error messages produced when something fails. Separated from stdout so errors don't corrupt clean data streams!
Step-by-step practical lab
Step 01: Inspect Linux Kernel Architecture & Compilation Target
සිංහලෙන් — Linux Kernel එකේ අනුවාදය සහ CPU Architecture එක පරීක්ෂා කරමු.
Query the running monolithic Linux kernel version, machine hardware name, and kernel build architecture.
uname -a-a: All: Kernel නම, nodename, kernel release, version සහ architecture (x86_64) සියල්ලම පෙන්වයි.
Expected output
Linux prod-app-srv-01 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC x86_64 GNU/LinuxSRE Tip: The x86_64 confirms a 64-bit Intel/AMD instruction set. For ARM AWS Graviton servers, you will see aarch64.
Step 02: Verify Linux Distribution Identity
සිංහලෙන් — Server එකේ ස්ථාපිත කර ඇති Linux මෙහෙයුම් පද්ධති සංස්කරණය (Distro) කියවීම.
Read the standard systemd OS release metadata file defining distribution name, version ID, and codename.
cat /etc/os-releasecat: ලිපිගොනුවක අන්තර්ගතය කෙලින්ම terminal තිරයට print කරයි.
Expected output
NAME="Ubuntu"
VERSION="24.04 LTS (Noble Numbat)"
ID=ubuntu
VERSION_ID="24.04"SRE Tip: Always verify the OS distribution before running package managers (apt for Ubuntu/Debian vs dnf/yum for RHEL/Amazon Linux).
Step 03: Check Server Uptime & CPU Load Averages
සිංහලෙන් — Server එක Restart නොවී වැඩ කළ කාලය සහ CPU බර (Load Average) මැනීම.
Display how long the Linux kernel has been running continuously, logged-in user count, and 1, 5, and 15-minute load averages.
uptimeuptime: පද්ධතියේ සක්රීය කාලය සහ CPU load averages (1m, 5m, 15m) ගණනය කරයි.
Expected output
12:51:04 up 14 days, 3:18, 2 users, load average: 0.18, 0.22, 0.19SRE Tip: If the load average exceeds the total physical CPU core count, processes are queuing and latency is degrading.
Hands-on practice activities
Work through these yourself — tick them off as you go.
- Activity 06: Redirect Command Output to File (Drill) — Use the > redirection operator to create a log file containing standard output text.
- Activity 07: Display File Content via Cat (Drill) — Print file content to stdout and verify your Linux operating system distribution identity.
- Activity 08: Test Command Piping Pipeline (Drill) — Pipe the full process list directly into the grep filter to isolate active Nginx master and worker processes.
- Activity 09: Distinguish > vs >> Redirection (Checkpoint) — Never use > on critical production logs because it wipes the file clean! Always use >> to safely append lines.
- Activity 10: Standard Error File Descriptor Check (Quiz) — What is the integer file descriptor number for standard error (stderr)? Answer: 2.
Keep going: ← Lab 01 · Lab 03 → · Track your progress in the Self Guide
ExerciseKnowledge check
What is the integer file descriptor number for standard error (stderr) in Linux? / Standard Error (stderr) සඳහා වෙන් කර ඇති File Descriptor අංකය කුමක්ද?
Finished this one?
Part of Self Guide · Stage 10: SRE Labs I — the machine underneath. Progress is saved in this browser.


