Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
AWS Certified Solutions Architect-Associate + AWS Certified Cloud Practitioner
Sanjeewani95
Updated:
Aug 19, 2026
🚀 එක පැකේජ් එකයි - මාසෙටම Unlimited Internet! 🌐
sayuru bandara
Updated:
Aug 18, 2026
🎬 CapCut Pro 1 Month Access! LKR 600
sayuru bandara
Updated:
Aug 18, 2026
🚀 Google One AI PRO Plan (Gemini Pro Activation) – 18 Months Access! LKR 2200
sayuru bandara
Updated:
Aug 18, 2026
Canva Pro Lifetime Own Mail Activation LKR 500
sayuru bandara
Updated:
Aug 18, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="ja2k17ja" data-source="post: 21849838" data-attributes="member: 562617"><p><strong>DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.</strong></p><p></p><p><span style="font-size: 15px"><u><strong>DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.</strong></u></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි අද කතාකරන්නේ I/O redirection සහ Piping පිලිබදවයි. </span></p><p><span style="font-size: 15px">මුලින්ම අපි Standard Input, Standard Output සහ Standard Error ගැන හොද අවබෝදයක් ලබාගනිමු. මම ඔයාලට මේ දේවල් ඉතාම සරල විදියට තේරුම් කරලා දෙන්නම්. ඔයාලට තියෙන්නෙ හොදට අවබෝද කරගෙන මම කියපු කරුණු මතකයේ තබාගෙන නිතර බාවිතා කරන එක.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මෙන්න මෙහෙමයි අපේ කතාන්දරය පටන් ගන්නේ. UNIX / Linux කමාන්ඩ් එකක් execute කලට පසු, kernel එක ස්වයන්ක්රියව files 3ක් open කරනව. අපි ඒ files වලට කියනව standard files කියල. ඒ file තුන තමා</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">පෙරනිමි ලෙස (By default) සියලුම UNIX / Linux කමාන්ඩ්ස් ඒවයෙ input ලබාගන්නෙ stdin (standard input) මගිනි, කමාන්ඩ්ස් වල result එක stdout (standard output) වෙත යොමුකරනව. ඒ වගේම යම්කිසි දෝෂයක් ඇතිවූ විට එය stderr (standard error) වෙත යොමුකරනව.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හොදින් මතක තියාගන්න අපි කමාන්ඩ්ස් රන් කරන terminal එක සමග මේ standard files තුන බද්දවෙලා තියෙනව කියල. පොඩ්ඩක් ඉන්න මම ඒ කතාව ටිකක් විස්තර කරන්නම්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි UNIX / Linux shell එකේ කමාන්ඩ් එකක් රන් කරනකොට එකට input එක දෙන්නෙ අපේ terminal එකට සම්බන්ද කරල තියෙන Keyboard එකෙන් සහ කමාන්ඩ් එකේ result එක හෝ දෝෂය (Error එක) terminal screen (Display) එකට යොමුවේ. මෙහිදී Keyboard එක stdin file එක සමගද terminal screen එක stdout හා stderr කියන file දෙක සමගද සම්බන්ද වී ඇත.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">තවද UNIX / Linux file system එක තුල ඕපන්කරන, සියලුම files සදහා file descriptor එකක් ලැබෙනවා. ඒ වගේම standard files සදහාද ඒවාට අවේනික වූ file descriptors තුනක් තියෙනව. මෙහිදී </span></p><p><span style="font-size: 15px">stdin හි file descriptor එක <strong>0</strong> ද, </span></p><p><span style="font-size: 15px">stdout හි file descriptor එක <strong>1</strong> ද, </span></p><p><span style="font-size: 15px">stderr හි file descriptor එක <strong>2</strong> ද වේ. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් බලමු මොදක්කද මේ <strong>file descriptors</strong> කියන්නේ කියල. අපි file descriptor එකක් කියල කියන්නෙ 0 පටන් ගෙන ආරෝහණ ක්රමයට වැඩිවෙන අංකයකට. මෙයින් 0, 1 සහ 3 කියන අංක ටික අනිවාර්යයෙන්ම standard files ෆයිල් තුනට හිමිවෙනව. මේ විදියට file descriptor එකක් දීමෙන් UNIX /Linux කර්නල් (kernel) එකට, එක් එක් file එක හදුනා ගැනීමට පුළුවන් වෙනව. සරලව කියනවනම් kernel එක තුල file එක සහ ඊට අදාල file descriptor සහිත table එකක් තියාගන්නව. දැන් හරිනේ ද ?</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මම මුලින් කිවුවනේ පෙරනිමි ලෙස stdin, stdout, stderr කියන standard files තුන පිලිවෙලින් terminal එකේ Keyboard, screen සහ නැවත screen එක සමග සම්බද වෙලා තියෙනවා කියල. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">නමුත් මේවා ස්ථිර ලෙසම සම්බන්ද වී නොමැත. අපිට stdin එකට input එකක් දීමට Keyboard එක වෙනුවට සාමාන්ය (ordinary) file එකක් පවා යොදා ගැනීමට පුළුවන්. ඒවගේම stdout සහ stderr එකේ output එක terminal screen එකට යොමු නොකර වෙනත් file එකකට හෝ නැතිනම් තවත් UNIX / Linux කමාන්ඩ් එකක input එකක් විදියට බාවිතා කරන්න (redirect) පුළුවන්.</span></p><p><span style="font-size: 15px">අපි මෙන්න මේ ක්රියාවලිට සිංහලෙන් කියනවා අයි ඕ රිඩිරේක්ෂන් කියල. English වලින් නම් <strong>I/O Redirection</strong>. අපිට මේවිදියට I/O Redirection කරන්න standard files තුනේ file descriptors ඉතා වැදගත් වෙනව.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් I/O Redirection කරන ආකාරය උදාහරණ සමගින් බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong><u>1) Input Redirection</u></strong></span></p><p> <span style="font-size: 15px">මෙහි දී අප කරනුයේ UNIX / Linux කමාන්ඩ් එකක input එක terminal keyboard එකෙන් නොදී file එකකින් ලබාදීමයි. Input Redirection එක ආකාර දෙකකට සිදුකල හැකිය.</span></p><p><span style="font-size: 15px">අප පළමු ක්රමයේදී "<span style="color: Red"><</span>" සංකේතය යොදා ගැනීමෙන් එය සිදුකරන අතර දෙවන ක්රමයේදී "<" සමග stdin හි file descriptor එක වන 0 යොදා ගැනීමත් (<span style="color: red">0<</span>) සිදු කරයි.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red"><</span> /etc/issue</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>grep "processor" < /proc/cpuinfo</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red">0<</span> /etc/issue</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>grep "processor" 0< /proc/cpuinfo</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඉහත උදාහරණ කිහිපයේ අපි input එක විදියට බාවිතා කළේ files කිහිපයකි. දැන් අපි දන්නව "<" හා "0<" මගින් Input Redirection සිදුකල හැකිබව.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong><u>2) Output Redirection</u></strong></span></p><p><span style="font-size: 15px">සරලව පැහැදිලි කරනවනම් අප මෙහිදී සිදුකරනුයේ කමාන්ඩ් එකක output එක terminal screen එකකට යොමු නොකර file එකකට හෝ වෙනත් කමාන්ඩ් එකකට යොමු කිරීමයි. මෙහිදී හොදින් මතක තියාගන්න. කමාන්ඩ් එකක output එක වෙනත් කමාන්ඩ් එකක input එකක් විදියට බාවිතා කිරීම අපි විශේෂ නමකින් හදුන් වනවා(pipe). අපි ඒ ගැන පසුව කතා කරමු. මෙහිදී output එක <strong>file එකකට</strong> යොමු කිරීම පමණක් Output Redirection එක යටතේ මම විස්තර කරනව. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපිට මෙයත් ආකාර දෙකකට සිදුකල හැක.</span></p><p><span style="font-size: 15px">අප පළමු ක්රමයේදී "<strong><span style="color: red">></span></strong>" සංකේතය යොදා ගැනීමෙන් එය සිදුකරන අතර දෙවන ක්රමයේදී ">" සමග stdout හි file descriptor එක වන 1 යොදා ගැනීමත් (<strong><span style="color: red">1></span></strong>) සිදු කරයි.</span></p><p><span style="font-size: 15px">අපි මුලින්ම පසුගිය පාඩමකදී සාදාගත් "lsmore" කියන ඩිරෙක්ටරි එකට මාරුවෙලා උදාහරණ ටික කරල බලමු .</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cd ~/lsmore</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපි Output Redirection උදාහරන ටික පටන්ගනිමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l <span style="color: red">></span> ~/ls_more_file_1.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මෙහිදී අප සිදු කරලා තියෙන්නේ ls -l කියන කමාන්ඩ් එකේ output එක terminal screen එකට යොමු නොකර කෙලින්ම එය "ls_more_file_1.txt" කියන file එකට යොමු කීරීමයි. හොදින් බලන්න ls_more_file_1.txt පිහිටලා තියෙන්නේ අපේ හෝම් (<strong>~</strong>) directory එක ඇතුලෙ. දැන් අපි ls_more_file_1.txt එකේ තියෙන්නේ මොනවද කියල බලමු. අපිට් ඒ සදහා </span></p><p><span style="font-size: 15px">cat < ~/ls_more_file_1.txt කියන කමාන්ඩ් එක යොදා හඳුනා පුළුවන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red"><</span> ~/ls_more_file_1.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැක්ක නේද ls -l කමාන්ඩ් එක දුන්නම කලින් screen එකේ පෙන්නන ටික දැන් file එක ඇතුලෙ තියෙනවා.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපිට <strong>1></strong> යොදා ගනිමින් ද මෙය සිදු කල හැකිය. </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>ls -l <span style="color: red">1></span> ~/ls_more_file_2.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් cat පාරක් දීල චෙක් කරලා බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < ~/ls_more_file_2.txt</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපිට වැඩේ පැහැදිලියි.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි තව දුරටත් උදාහරණ කිහිපයක් කරමු.</span></p><p><span style="font-size: 15px">අපි මුලින්නම cd ~/lsmore කරලා lsmore ඩිරෙක්ටරි එක ඇතුලට යමු. ඉන් අනතුරුව cat <span style="color: red">></span> stdout_example1 (හෝ cat <span style="color: red">1></span> stdout_example1) කියල ටයිප් කරලා Enter කි එක press කරන්න. </span></p><p><span style="font-size: 15px">දැන් අපිට මේ ටික terminal එකේ ටයිප් කරන්න පුළුවන්. අන්තිම line එකත් ටයිප් කරල Enter කි එකත් ඔබල අන්තිමට Ctrl කි එක සමග d කි එක press කරන්න (Ctrl d). මෙන්න මේ විදියට</span></p><p> <span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red">></span> stdout_example1</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපිට cat ම යොදාගෙන (Input Redirection මගින්) stdout_example1 ඇතුලේ තියෙන දේවල් බලාගන්න පුළුවන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red"><</span> stdout_example1</strong> හෝ <strong>cat <span style="color: red">0<</span> stdout_example1</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">මේකත් ට්රයි කරලා බලන්න </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් බලමු "Input Redirection" හා "Output Redirection" දෙකම එක විට යොදාගන්නා ආකාරය.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat <span style="color: red"><</span> stdout_example1 <span style="color: Blue">></span> stdout_example2</strong> හෝ <strong>cat <span style="color: Red">0<</span> stdout_example1 <span style="color: blue">1></span> stdout_example2</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">අපි දැන් බලමු stdout එක විදියට දුන්න stdout_example2 එක ඇතුලෙ මොනවද තියෙන්නෙ කියල . cat පාරක් දීල බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හ්ම් දැන් අපිට තියෙනවා <span style="color: Red">stdout_example1</span> වගේම <span style="color: Blue">stdout_example2</span> කියල අලුත් ෆයිල් එකක්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඉහත උදාහරණයේදී මම කරලා තියෙන දේ පොඩ්ඩක් පැහැදිලි කරන්නම්. අපි මුලින්ම මෙන්න මේ කොටස ගනිමු. "<span style="color: Red"><strong><</strong></span> <span style="color: red">stdout_example1</span>" අපි මෙහිදී කරලා තියෙන්නෙ stdin එක redirect කරලා තියෙනව <span style="color: Red">stdout_example1</span> කියන ෆයිල් එකට අපි එය කලින් හදපු file එකක්. එවිට cat කමාන්ඩ් එක input එක විදියට ගන්නෙ මෙන්න මේ <span style="color: red">stdout_example1</span> එක. දැන් බලමු මේ කොටස "<span style="color: Blue"><strong>></strong></span> <span style="color: Blue">stdout_example2</span>" මෙහිදී අපි කරලා තියෙන්නෙ cat හි stdout එක redirect කරල තියෙනව "<span style="color: blue">stdout_example2</span>" කියන file එකට. අන්තිමට අපිට ලැබුන stdout_example1 එකට <strong>සමාන</strong> stdout_example2 කියල file එකක්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">හොදින් මතක තියාගන්න. මෙවගේ Input සහ Output redirection දෙකම එකවිට ඇතිවිට "<" (Input Redirection) එක මුලින්ම කරන්න ඕන කියල දෙයක් නැ. අපිට ඉහත කරපු දේ මේ විදියටත් කරන්න පුළුවන්.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat > stdout_example3 < stdout_example1</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">cat දීල චෙක් කරගමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example3</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් අපි බලමු <strong>Appending Output Redirection</strong> කියන එක ගැන . අපි මේ සදහා<strong> >></strong> හෝ <strong>1>></strong> යොදාගන්නව.</span></p><p><span style="font-size: 15px">මම දෙන උදාහරණය බලල ඔයාලම තේරුම් ගන්න උත්සහ කරන්න.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example1 <span style="color: Red">></span> stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">නැවත වරක් </span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example1 <span style="color: red">></span> stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">නැවත වරක් cat පාරක් දල බලමු </span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ඉහත අවස්ථා දෙකම එක වගේ ප්රතිපල තියෙන්නෙ.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><strong>දැන් අපි බලමු Appending Output Redirection (<strong>>></strong>) එක බාවිතා කරල</strong> </span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example1 <span style="color: Lime">>></span> stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් cat පාරක් දාල ඇතුලේ තියෙන්නෙ මොනවද කියල බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">එවර අපිට ලොකු වෙනසක් පේනව. </span></p><p><span style="font-size: 15px">අපි තවත් වරක් "cat < stdout_example1 >> stdout_example4" කමාන්ඩ් එක දීල බලමු.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">ට්රයි <strong>cat < stdout_example1 <span style="color: red">>></span> stdout_example4</strong> හෝ <strong>cat < stdout_example1 <span style="color: red">1>></span> stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">නැවත ට්රයි <strong>cat < stdout_example4</strong></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">දැන් මෙතන වෙන දේ ඔයාලට හොදට තේරුණා නේද. <span style="color: Blue">>></span>" එක යොදනවිට file name එකට සමාන file එකක් ඩිරෙක්ටරිය ඇතුලෙ තිබුනොත් එම file එක overwrite <strong>නොකර</strong> එහි අගට අලුත් දේවල් එකතු කරනව කියල. "<span style="color: Red">></span>" යෙදුවිට තිබුන file එක overwrite වෙනව. <strong>">" හා ">>" යන දෙකටම අපි දෙන file name එක සහිත file එකක් නොමතිනම්. එම නමින් අලුතින් file එකක් හදාගන්න පුළුවන්</strong>.</span></p></blockquote><p></p>
[QUOTE="ja2k17ja, post: 21849838, member: 562617"] [b]DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.[/b] [SIZE="4"][U][B]DevOps_UNIX / Linux_8_I/O_රිඩිරෙක්ෂන්_සහ_Piping.[/B][/U] අපි අද කතාකරන්නේ I/O redirection සහ Piping පිලිබදවයි. මුලින්ම අපි Standard Input, Standard Output සහ Standard Error ගැන හොද අවබෝදයක් ලබාගනිමු. මම ඔයාලට මේ දේවල් ඉතාම සරල විදියට තේරුම් කරලා දෙන්නම්. ඔයාලට තියෙන්නෙ හොදට අවබෝද කරගෙන මම කියපු කරුණු මතකයේ තබාගෙන නිතර බාවිතා කරන එක. මෙන්න මෙහෙමයි අපේ කතාන්දරය පටන් ගන්නේ. UNIX / Linux කමාන්ඩ් එකක් execute කලට පසු, kernel එක ස්වයන්ක්රියව files 3ක් open කරනව. අපි ඒ files වලට කියනව standard files කියල. ඒ file තුන තමා පෙරනිමි ලෙස (By default) සියලුම UNIX / Linux කමාන්ඩ්ස් ඒවයෙ input ලබාගන්නෙ stdin (standard input) මගිනි, කමාන්ඩ්ස් වල result එක stdout (standard output) වෙත යොමුකරනව. ඒ වගේම යම්කිසි දෝෂයක් ඇතිවූ විට එය stderr (standard error) වෙත යොමුකරනව. හොදින් මතක තියාගන්න අපි කමාන්ඩ්ස් රන් කරන terminal එක සමග මේ standard files තුන බද්දවෙලා තියෙනව කියල. පොඩ්ඩක් ඉන්න මම ඒ කතාව ටිකක් විස්තර කරන්නම්. අපි UNIX / Linux shell එකේ කමාන්ඩ් එකක් රන් කරනකොට එකට input එක දෙන්නෙ අපේ terminal එකට සම්බන්ද කරල තියෙන Keyboard එකෙන් සහ කමාන්ඩ් එකේ result එක හෝ දෝෂය (Error එක) terminal screen (Display) එකට යොමුවේ. මෙහිදී Keyboard එක stdin file එක සමගද terminal screen එක stdout හා stderr කියන file දෙක සමගද සම්බන්ද වී ඇත. තවද UNIX / Linux file system එක තුල ඕපන්කරන, සියලුම files සදහා file descriptor එකක් ලැබෙනවා. ඒ වගේම standard files සදහාද ඒවාට අවේනික වූ file descriptors තුනක් තියෙනව. මෙහිදී stdin හි file descriptor එක [B]0[/B] ද, stdout හි file descriptor එක [B]1[/B] ද, stderr හි file descriptor එක [B]2[/B] ද වේ. අපි දැන් බලමු මොදක්කද මේ [B]file descriptors[/B] කියන්නේ කියල. අපි file descriptor එකක් කියල කියන්නෙ 0 පටන් ගෙන ආරෝහණ ක්රමයට වැඩිවෙන අංකයකට. මෙයින් 0, 1 සහ 3 කියන අංක ටික අනිවාර්යයෙන්ම standard files ෆයිල් තුනට හිමිවෙනව. මේ විදියට file descriptor එකක් දීමෙන් UNIX /Linux කර්නල් (kernel) එකට, එක් එක් file එක හදුනා ගැනීමට පුළුවන් වෙනව. සරලව කියනවනම් kernel එක තුල file එක සහ ඊට අදාල file descriptor සහිත table එකක් තියාගන්නව. දැන් හරිනේ ද ? මම මුලින් කිවුවනේ පෙරනිමි ලෙස stdin, stdout, stderr කියන standard files තුන පිලිවෙලින් terminal එකේ Keyboard, screen සහ නැවත screen එක සමග සම්බද වෙලා තියෙනවා කියල. නමුත් මේවා ස්ථිර ලෙසම සම්බන්ද වී නොමැත. අපිට stdin එකට input එකක් දීමට Keyboard එක වෙනුවට සාමාන්ය (ordinary) file එකක් පවා යොදා ගැනීමට පුළුවන්. ඒවගේම stdout සහ stderr එකේ output එක terminal screen එකට යොමු නොකර වෙනත් file එකකට හෝ නැතිනම් තවත් UNIX / Linux කමාන්ඩ් එකක input එකක් විදියට බාවිතා කරන්න (redirect) පුළුවන්. අපි මෙන්න මේ ක්රියාවලිට සිංහලෙන් කියනවා අයි ඕ රිඩිරේක්ෂන් කියල. English වලින් නම් [B]I/O Redirection[/B]. අපිට මේවිදියට I/O Redirection කරන්න standard files තුනේ file descriptors ඉතා වැදගත් වෙනව. අපි දැන් I/O Redirection කරන ආකාරය උදාහරණ සමගින් බලමු. [B][U]1) Input Redirection[/U][/B] මෙහි දී අප කරනුයේ UNIX / Linux කමාන්ඩ් එකක input එක terminal keyboard එකෙන් නොදී file එකකින් ලබාදීමයි. Input Redirection එක ආකාර දෙකකට සිදුකල හැකිය. අප පළමු ක්රමයේදී "[COLOR="Red"]<[/COLOR]" සංකේතය යොදා ගැනීමෙන් එය සිදුකරන අතර දෙවන ක්රමයේදී "<" සමග stdin හි file descriptor එක වන 0 යොදා ගැනීමත් ([COLOR="red"]0<[/COLOR]) සිදු කරයි. ට්රයි [B]cat [COLOR="red"]<[/COLOR] /etc/issue[/B] ට්රයි [B]grep "processor" < /proc/cpuinfo[/B] ට්රයි [B]cat [COLOR="red"]0<[/COLOR] /etc/issue[/B] ට්රයි [B]grep "processor" 0< /proc/cpuinfo[/B] ඉහත උදාහරණ කිහිපයේ අපි input එක විදියට බාවිතා කළේ files කිහිපයකි. දැන් අපි දන්නව "<" හා "0<" මගින් Input Redirection සිදුකල හැකිබව. [B][U]2) Output Redirection[/U][/B] සරලව පැහැදිලි කරනවනම් අප මෙහිදී සිදුකරනුයේ කමාන්ඩ් එකක output එක terminal screen එකකට යොමු නොකර file එකකට හෝ වෙනත් කමාන්ඩ් එකකට යොමු කිරීමයි. මෙහිදී හොදින් මතක තියාගන්න. කමාන්ඩ් එකක output එක වෙනත් කමාන්ඩ් එකක input එකක් විදියට බාවිතා කිරීම අපි විශේෂ නමකින් හදුන් වනවා(pipe). අපි ඒ ගැන පසුව කතා කරමු. මෙහිදී output එක [B]file එකකට[/B] යොමු කිරීම පමණක් Output Redirection එක යටතේ මම විස්තර කරනව. අපිට මෙයත් ආකාර දෙකකට සිදුකල හැක. අප පළමු ක්රමයේදී "[B][COLOR="red"]>[/COLOR][/B]" සංකේතය යොදා ගැනීමෙන් එය සිදුකරන අතර දෙවන ක්රමයේදී ">" සමග stdout හි file descriptor එක වන 1 යොදා ගැනීමත් ([B][COLOR="red"]1>[/COLOR][/B]) සිදු කරයි. අපි මුලින්ම පසුගිය පාඩමකදී සාදාගත් "lsmore" කියන ඩිරෙක්ටරි එකට මාරුවෙලා උදාහරණ ටික කරල බලමු . ට්රයි [B]cd ~/lsmore[/B] දැන් අපි Output Redirection උදාහරන ටික පටන්ගනිමු. ට්රයි [B]ls -l [COLOR="red"]>[/COLOR] ~/ls_more_file_1.txt[/B] මෙහිදී අප සිදු කරලා තියෙන්නේ ls -l කියන කමාන්ඩ් එකේ output එක terminal screen එකට යොමු නොකර කෙලින්ම එය "ls_more_file_1.txt" කියන file එකට යොමු කීරීමයි. හොදින් බලන්න ls_more_file_1.txt පිහිටලා තියෙන්නේ අපේ හෝම් ([B]~[/B]) directory එක ඇතුලෙ. දැන් අපි ls_more_file_1.txt එකේ තියෙන්නේ මොනවද කියල බලමු. අපිට් ඒ සදහා cat < ~/ls_more_file_1.txt කියන කමාන්ඩ් එක යොදා හඳුනා පුළුවන්. ට්රයි [B]cat [COLOR="red"]<[/COLOR] ~/ls_more_file_1.txt[/B] දැක්ක නේද ls -l කමාන්ඩ් එක දුන්නම කලින් screen එකේ පෙන්නන ටික දැන් file එක ඇතුලෙ තියෙනවා. අපිට [B]1>[/B] යොදා ගනිමින් ද මෙය සිදු කල හැකිය. ට්රයි [B]ls -l [COLOR="red"]1>[/COLOR] ~/ls_more_file_2.txt[/B] දැන් cat පාරක් දීල චෙක් කරලා බලමු. ට්රයි [B]cat < ~/ls_more_file_2.txt[/B] දැන් අපිට වැඩේ පැහැදිලියි. අපි තව දුරටත් උදාහරණ කිහිපයක් කරමු. අපි මුලින්නම cd ~/lsmore කරලා lsmore ඩිරෙක්ටරි එක ඇතුලට යමු. ඉන් අනතුරුව cat [COLOR="red"]>[/COLOR] stdout_example1 (හෝ cat [COLOR="red"]1>[/COLOR] stdout_example1) කියල ටයිප් කරලා Enter කි එක press කරන්න. දැන් අපිට මේ ටික terminal එකේ ටයිප් කරන්න පුළුවන්. අන්තිම line එකත් ටයිප් කරල Enter කි එකත් ඔබල අන්තිමට Ctrl කි එක සමග d කි එක press කරන්න (Ctrl d). මෙන්න මේ විදියට ට්රයි [B]cat [COLOR="red"]>[/COLOR] stdout_example1[/B] දැන් අපිට cat ම යොදාගෙන (Input Redirection මගින්) stdout_example1 ඇතුලේ තියෙන දේවල් බලාගන්න පුළුවන්. ට්රයි [B]cat [COLOR="red"]<[/COLOR] stdout_example1[/B] හෝ [B]cat [COLOR="red"]0<[/COLOR] stdout_example1[/B] මේකත් ට්රයි කරලා බලන්න අපි දැන් බලමු "Input Redirection" හා "Output Redirection" දෙකම එක විට යොදාගන්නා ආකාරය. ට්රයි [B]cat [COLOR="red"]<[/COLOR] stdout_example1 [COLOR="Blue"]>[/COLOR] stdout_example2[/B] හෝ [B]cat [COLOR="Red"]0<[/COLOR] stdout_example1 [COLOR="blue"]1>[/COLOR] stdout_example2[/B] අපි දැන් බලමු stdout එක විදියට දුන්න stdout_example2 එක ඇතුලෙ මොනවද තියෙන්නෙ කියල . cat පාරක් දීල බලමු. හ්ම් දැන් අපිට තියෙනවා [COLOR="Red"]stdout_example1[/COLOR] වගේම [COLOR="Blue"]stdout_example2[/COLOR] කියල අලුත් ෆයිල් එකක්. ඉහත උදාහරණයේදී මම කරලා තියෙන දේ පොඩ්ඩක් පැහැදිලි කරන්නම්. අපි මුලින්ම මෙන්න මේ කොටස ගනිමු. "[COLOR="Red"][B]<[/B][/COLOR] [COLOR="red"]stdout_example1[/COLOR]" අපි මෙහිදී කරලා තියෙන්නෙ stdin එක redirect කරලා තියෙනව [COLOR="Red"]stdout_example1[/COLOR] කියන ෆයිල් එකට අපි එය කලින් හදපු file එකක්. එවිට cat කමාන්ඩ් එක input එක විදියට ගන්නෙ මෙන්න මේ [COLOR="red"]stdout_example1[/COLOR] එක. දැන් බලමු මේ කොටස "[COLOR="Blue"][B]>[/B][/COLOR] [COLOR="Blue"]stdout_example2[/COLOR]" මෙහිදී අපි කරලා තියෙන්නෙ cat හි stdout එක redirect කරල තියෙනව "[COLOR="blue"]stdout_example2[/COLOR]" කියන file එකට. අන්තිමට අපිට ලැබුන stdout_example1 එකට [B]සමාන[/B] stdout_example2 කියල file එකක්. හොදින් මතක තියාගන්න. මෙවගේ Input සහ Output redirection දෙකම එකවිට ඇතිවිට "<" (Input Redirection) එක මුලින්ම කරන්න ඕන කියල දෙයක් නැ. අපිට ඉහත කරපු දේ මේ විදියටත් කරන්න පුළුවන්. ට්රයි [B]cat > stdout_example3 < stdout_example1[/B] cat දීල චෙක් කරගමු. ට්රයි [B]cat < stdout_example3[/B] දැන් අපි බලමු [B]Appending Output Redirection[/B] කියන එක ගැන . අපි මේ සදහා[B] >>[/B] හෝ [B]1>>[/B] යොදාගන්නව. මම දෙන උදාහරණය බලල ඔයාලම තේරුම් ගන්න උත්සහ කරන්න. ට්රයි [B]cat < stdout_example1 [COLOR="Red"]>[/COLOR] stdout_example4[/B] ට්රයි [B]cat < stdout_example4[/B] නැවත වරක් ට්රයි [B]cat < stdout_example1 [COLOR="red"]>[/COLOR] stdout_example4[/B] නැවත වරක් cat පාරක් දල බලමු ට්රයි [B]cat < stdout_example4[/B] ඉහත අවස්ථා දෙකම එක වගේ ප්රතිපල තියෙන්නෙ. [B]දැන් අපි බලමු Appending Output Redirection ([B]>>[/B]) එක බාවිතා කරල[/B] ට්රයි [B]cat < stdout_example1 [COLOR="Lime"]>>[/COLOR] stdout_example4[/B] දැන් cat පාරක් දාල ඇතුලේ තියෙන්නෙ මොනවද කියල බලමු. ට්රයි [B]cat < stdout_example4[/B] එවර අපිට ලොකු වෙනසක් පේනව. අපි තවත් වරක් "cat < stdout_example1 >> stdout_example4" කමාන්ඩ් එක දීල බලමු. ට්රයි [B]cat < stdout_example1 [COLOR="red"]>>[/COLOR] stdout_example4[/B] හෝ [B]cat < stdout_example1 [COLOR="red"]1>>[/COLOR] stdout_example4[/B] නැවත ට්රයි [B]cat < stdout_example4[/B] දැන් මෙතන වෙන දේ ඔයාලට හොදට තේරුණා නේද. [COLOR="Blue"]>>[/COLOR]" එක යොදනවිට file name එකට සමාන file එකක් ඩිරෙක්ටරිය ඇතුලෙ තිබුනොත් එම file එක overwrite [B]නොකර[/B] එහි අගට අලුත් දේවල් එකතු කරනව කියල. "[COLOR="Red"]>[/COLOR]" යෙදුවිට තිබුන file එක overwrite වෙනව. [B]">" හා ">>" යන දෙකටම අපි දෙන file name එක සහිත file එකක් නොමතිනම්. එම නමින් අලුතින් file එකක් හදාගන්න පුළුවන්[/B].[/SIZE] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom