Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts

Friday, March 30, 2012

Linux commands (2)

အသုံးတည့္တဲ့ Linux command ေလးေတြ ၊ bash shell မွာ သုံးလို႕ရတဲ့ ပံုစံေလးေတြ ဟိုးအရင္ကေရးဖူးပါတယ္ ။

Linux commands (1)

အခုက်ေနာ္တို႕ ေန႕စဥ္ အသုံးမ်ားတဲ့ command ေလးေတြကို ၾကည့္ရေအာင္။

top
 top command က Linux မွာေတာ့ Task Manager ပါပဲ။ လက္ရွိ run ေနတဲ့ process ေတြရဲ့ PID ေတြ CPU usage ၊ Memory usage ေတြျပပါတယ္ ။ Process တစ္ခုခုက CPU usage အရမ္းမ်ားေနသလား ၊ လိုအပ္တာထက္ျပီျပီး memory usage တက္ေနလား top ကေနၾကည့္ေလ့ရွိပါတယ္။

ဒါ Linux Administrator ေတြ အလုပ္လုပ္ခ်င္ေယာင္ေဆာင္တဲ့ command ပါ။ ဘာအလုပ္မွ မရွိရင္ terminal ေလးတစ္ခုဖြင့္ top ေလး run ထားျပီး အလုပ္လုပ္ေနသလိုလို အေယာင္ေဆာင္ေနလို႕ရတယ္။ Process ေတြက တက္လာလိုက္ ေပ်ာက္သြားလိုက္ေန ၊ terminal ေပၚမွာ ရွုပ္ေနေတာ့ မသိတဲ့လူၾကည့္ရင္ အလုပ္ေတြ လုပ္ေနတယ္ထင္မွာပဲ။

kill / killall
Process တစ္ခုခု hang ေနရင္ပဲျဖစ္ျဖစ္ ၊ မလိုအပ္တဲ့ process မို႕လို႕ end လုပ္ခ်င္ရင္ပဲျဖစ္ျဖစ္ linux မွာေတာ့ kill တယ္လို႕ သုံးပါတယ္။ kill နဲ႕ killall ဘာကြာလည္းဆို ေယဘူရေျပာရရင္ေတာ့ kill က PID နဲ႕ kill ရျပီးေတာ့ killall ကေတာ့ process name နဲ႕ သုံးပါတယ္။ killall မွာ interactive mode တို႕ ၊ specific user's process ပဲ kill တာတို႕လုပ္လို႕ရပါတယ္ ။

man
Nix user ေတြ Admin ေတြ ဘယ္လိုမွ ကင္းရွင္းေအာင္ေနလို႕မရတဲ့ command ပါပဲ။ Command တစ္ခုခုရဲ့ sub command ေတြ parameter ေတြ syntax ေတြေမ့ေနရင္ man နဲ႕ ျပန္ၾကည့္ရတာပဲ။ Manual ဆိုတဲ့ စကားလုံးကို အတိုေခၚတာပါ။ Man page လို႕ေခၚတဲ့ command manual ကို ျပန္ေဖာ္ျပပါတယ္။

ls
ေန႕တိုင္း သုံးၾကတဲ့ command တစ္ခုပါ။ DOS ရဲ့ dir command ရဲ့ Linux version ေပါ့။ List ဆိုတဲ့ စကားလုံးကို အတိုယူထားတာပါ။ ls ပဲ႐ိုက္ရင္ file / folder list ပဲျပပါတယ္။ ls -l ဆိုရင္ေတာ့ file size ေတြ ၊ time stamp ေတြနဲ႕ျပပါတယ္။ File size ကို MB ေတြ GB ေတြနဲ႕ ျပေစခ်င္ရင္ ls -lh လို႕ ႐ိုက္ရပါတယ္။

pwd
လက္ရွိ ကိုယ္ဘယ္ path ေအာက္မွာ ေရာက္ေနလည္း ျပန္ျပန္ၾကည့္တဲ့ command ပါ။ Print Working Directory ဆိုတာကို အတိုေခၚတာပါ။ တစ္ခါတစ္ေလ ကိုယ့္ home directory ထဲက backup file ကို ျပင္ေနမိတာလား ၊ /etc/ ေအာက္က တကယ့္ config file ကို ျပင္ေနမိတာလားမေသခ်ာရင္ ကိုယ္ဘယ္ေရာက္ေနလည္း ျပန္ၾကည့္ရတာေပါ့ ။

Linux command ေတြက ေျပာရရင္ အမ်ားၾကီးပါ ။ ေန႕တိုင္း သုံးျဖစ္တာေလးေတြေလာက္ပဲ အခု ေရးထားတာပါ ။ ေန႕တိုင္းမဟုတ္ေပမဲ့ မၾကာမၾကာ သုံးတဲ့ less / more တို႕ tar တို႕ tail / head တို႕ ေနာက္မွ ေရးေတာ့မယ္ ။ Linux command list ကို ဒီေအာက္က link မွာ ၾကည့္ႏိုင္ပါတယ္ ။
http://www.oreillynet.com/linux/cmd/

Friday, May 6, 2011

Geez, what hardware spec i've got there ?

တစ္ခါတစ္ေလ Server ေတြရဲ့ Hardware spec ျပန္ၾကည့္ခ်င္တယ္၊ Serial Number ျပန္ၾကည့္ခ်င္တယ္၊ Server ကလည္း အနားမွာမရွိဘူး ၊ က်ေနာ္လို႕ documentation ေကာင္းရင္ ဘာ server သုံးခဲ့မိမွန္းေတာင္ မမွတ္မိေတာ့ဘူးဆိုရင္ command line ကေန ၾကည့္လို႕ရပါတယ္။ အမ်ားဆုံးျဖစ္တတ္တာက က်ေနာ္တို႕ဆို memory upgrade လုပ္ခ်င္တာ၊ memory type သိခ်င္ရုံနဲ႕လည္း Data center အထိမသြားခ်င္၊ သြားျဖစ္လည္း ဒါေလးအတြက္နဲ႕ BIOS ထဲဝင္မၾကည့္ခ်င္ရင္ အသုံးတဲ့ပါတယ္။

Linux မွာေတာ့ dmidecode command က ေတာ္ေတာ္အသုံးဝင္ပါတယ္။
Serial number ေလာက္ျပန္ၾကည့္ခ်င္တာဆို
# dmidecode --type 1

လို႕႐ိုက္လိုက္ရင္ Chassis က serial number ကိုျပေပးပါတယ္။ Memory slot ေတြနဲ႕ ပတ္သက္တယ့္ information က type 16 ျဖစ္ေလ့ရွိပါတယ္။ Slot အေရအတြက္နဲ႕ Max capacity ျပပါလိမ့္မယ္။ အခုလက္ရွိတပ္ထားတယ့္ memory ကိုၾကည့္ခ်င္ရင္ေတာ့ Server အဖုံးဖြင့္ၾကည့္ရပါတယ္။ အခုလက္ရွိ တပ္ထားတယ့္ memory ရဲ့ information ေလာက္ပဲၾကည့္ခ်င္ရင္ေတာ့ 'dmidecode --type 17' ဆိုရင္ရပါတယ္။ DDR အမ်ိဳးအစားနဲ႕ speed ကိုျပပါလိမ့္မယ္။

Type နံပါတ္မေသခ်ာရင္လည္း dmidecode ရဲ့ output တစ္ခုလုံးကို output pipe နဲ႕ more ဒါမွမဟုတ္ less ဆိုျပီး ၾကည့္ရင္လည္းရပါတယ္။ Output ကရွင္းပါတယ္ ၊ လိုတယ့္ information ကိုရွာလို႕ လြယ္ပါတယ္။ ဒါဆို command က ဒါမ်ိဳးေပါ့။
# dmidecode | less


Linux ရဲ့ dmidecode ကေတာ့ hardware info ကိုပဲ အဓိကျပပါတယ္။

Windows မွာဆိုရင္ေတာ့ wmic ဆိုတယ့္ command တစ္ခု ပါပါတယ္။ Windows Management Instrumentation ေပၚမွာ အေျခခံထားတယ့္ command ပါ။ wmic command output ကရွုပ္လို႕ တစ္ခါမွ လိုက္မၾကည့္ဖူးပါဘူး။ လိုတာပဲမွတ္ထားမိတယ္။ ဒါေပမယ့္ သူကေတာ့ ပိုျပီး information မ်ားမ်ား retrieve လုပ္ႏိုင္ပါတယ္။

Serial number ကေတာ့ BIOS မွာရွိပါတယ္ ။
> wmic bios

ဆိုရင္ မ်က္စိေနာက္စရာ output နဲ႕ျပပါတယ္။ လိုခ်င္တာေလးျပန္ ျဖတ္ၾကည့္ရတယ္။
> wmic bios get serialnumber

ဒါမွ လိုခ်င္တာေလးျပတယ္။

Memory speed ကေတာ့ memorychip ထဲမွာပါ။
> wmic memorychip get speed

ဒါမွမဟုတ္ပဲ တျခားဘာေတြရွိေသးလည္းၾကည့္ခ်င္ရင္ ေနာက္က get speed ျဖဳတ္႐ိုက္ေပါ့။ အဲ Memory capacity က်ေတာ့ memphysical ထဲမွာ ။
>wmic memphysical get maxcapacity

ဆိုရင္ maximum capacity ျပျပီး ၊
>wmic memphysical get memorydevices

ဆိုရင္ slot ဘယ္နခုရွိလည္း ျပပါတယ္။

WMIC က hardware info retrieve လုပ္ဖို႕ေလာက္ လုပ္ထားတာမဟုတ္ပဲ current system ရဲ့ info ေတာ္ေတာ္မ်ားမ်ား process info ေတြ ၊ partition table ေတြပါၾကည့္လို႕ရပါတယ္။ WMIC အေၾကာင္းထပ္သိခ်င္ေသးရင္ ဒီ link မွာ ရွိပါေသးတယ္။ အေသးစိတ္ကေတာ့ Google ကရွာျပီး Microsoft technet article သာရွာဖတ္ၾကည့္ေပါ့။

http://www.robvanderwoude.com/ntadmincommands.php

အသုံးတဲ့မယ္ထင္ပါတယ္။ မတဲ့လည္း သုံးၾကည့္ေပါ့ ။ :D

Divinity

Wednesday, April 27, 2011

Make your own shutdown command :D

စာေရးမယ္ ေျပာတုန္းကေျပာျပီး ေရးဖို႕ၾက ပ်င္းတယ္။ Game က လည္း ဆက္ကစားရအုန္းမယ္ ။ အခ်ိန္ေတြက ေလာက္ကို မေလာက္ဖူး ။ ေခါင္းစဥ္ဖတ္ျပီး ၾကီးၾကီးက်ယ္က်ယ္ေတာ့ မထင္ပါနဲ႕ ။ Linux ေပၚမွာ ေပါက္ကရ ေပါက္စေလးတစ္ခုေလာက္ လုပ္ၾကည့္ရေအာင္။

Bash မွာ command alias ေလးတစ္ခုေလာက္ ေရးၾကည့္ရေအာင္ ။ ကိုယ့္နာမည္႐ိုက္လိုက္ရင္ laptop က shutdown က်သြားတာမ်ိဳးေလးဆို မဆိုးဘူး။
$HOME ရဲ့ေအာက္မွာ .bash_profile သို႕မဟုတ္ .profile ဆိုတယ့္ file ရွိပါတယ္။ Bash shell မွာ .bash_profile လို႕ေတြ႕ရျပီး Sh မွာေတာ့ .profile လို႕ေတြ႕ရပါတယ္။ ( မိုးေလဝသ ေၾကညာတယ့္ ေလသံမ်ားေပါက္သြားလားမသိဘူး) Filename မွာ ေရွ႕မွာ full stop ပါပါတယ္။ ဒါ nix မွာ ေတာ့ hidden attribute ပါ။ ls နဲ႕ၾကည့္ရင္ ls -a ဆိုမွ ျမင္ရပါလိမ့္မယ္။ ကဲ အဲဒီ file ကို edit လုပ္ၾကမယ္။ vi ပဲျဖစ္ျဖစ္ vim ပဲျဖစ္ျဖစ္ nano ပဲျဖစ္ျဖစ္ ၾကိဳက္ရာနဲ႕ ဖြင့္၊ edit ျပီး save လို႕ရရင္ ျပီးတာပဲ။ ျပီးရင္ ဒီ ႏွစ္လိုင္းကို ေအာက္ဆုံးမွာ ျဖည့္လိုက္ပါ။

gant=`which shutdown`
alias divinity='$gant -h now'


Generic ျဖစ္ေအာင္ ႏွစ္လိုင္းေရးလိုက္တာပါ။ Shutdown file ရွိတယ့္ path ကိုတန္းေပးျပီး $gant လို႕ မေပးေတာ့ရင္လည္း ရပါတယ္။ divinity ေနရာကေတာ့ ကိုယ့္နာမည္ ကိုေျပာင္းေပါ့။ Save လုပ္ျပီးရင္ စမ္းခ်င္ရင္ logout ျပီး ျပန္ login ဝင္ရပါတယ္။ Shell environment ကို edit တာမို႕ ခ်က္ခ်င္း effective မျဖစ္ပဲ next login မွာမွ effective ျဖစ္ပါတယ္။ ကဲ အခုဆိုရင္ေတာ့ ကိုယ့္နာမယ္ ကိုယ္႐ိုက္ျပီး shutdown ခ်လို႕ ရပါျပီ ။ ( စားၾကမယ္ေဟ့ ေကာင္းေကာင္း ေလသံေပါက္သြားလားမသိ )


Divinity

Thursday, July 29, 2010

Linux commands (1)

Linux console ေပၚမွာ အလုပ္လုပ္တယ့္ အခါ တစ္ခ်ိဳ႕ command ေတြက သိထားရင္ command line interface မွာ အေတာ္အသုံးဝင္ပါတယ္။ မသိလည္းရတယ္ ၊ သိရင္ ပိုအဆင္ေျပတယ့္ command ေလးေတြေပါ့။ နည္းနည္းခ်င္း ေခါင္းထဲေပၚလာသေလာက္ ေရးသြားပါမယ္။

...........
Log file လိုဟာမ်ိဳးကို ဖတ္တယ့္အခါမွာ tail command ကသုံးဝင္ပါတယ္ ။ ဆိုၾကပါေတာ့၊ httpd ရဲ့ access_log file ။ Apache process run ေနျပီး user ေတြက access လုပ္ေနတိုင္း access_log ကေရးေနပါတယ္။ ဒီလို log မ်ိဳးရဲ့ ေနာက္ဆုံး process ေတြ log ကို လိုခ်င္ရင္ အလြယ္တကူက `cat /var/log/httpd/access_log ဆိုျပီး cat ထုတ္လိုက္တာမ်ိဳး ၊ tail -n50 /var/log/httpd/access_log ဆိုျပီး ေနာက္ဆုံး လိုင္း 50 ေခၚၾကည့္တာတို႕ လုပ္လိုက္တာမ်ားတယ္။ ဒါေတြက ဒီ command ကို ႐ိုက္လိုက္တယ့္ အခ်ိန္က log ထဲမွာရွိတာကိုျပတာပါ။ Real time ေတာက္ေလွ်ာက္လာေရးေနတာကို ဖတ္ခ်င္ရင္ေတာ့
tail -f /var/log/httpd/access_log

ဆိုျပီး tail -f ကိုသုံးပါတယ္။ ဒါဆို console ထဲမွာ log file ကပြင့္လာျပီး log မွာ တစ္လိုင္းအသစ္လာေရးတိုင္း တစ္လိုင္းတက္တက္လာတယ္။ ဒါဆို debug လုပ္ဖို႕ ပို အဆင္ေျပပါတယ္။

........
တစ္ခါတစ္ေလ log file ( text file တစ္ခုခုေပါ့) ကို ရွင္းလိုက္ခ်င္တာမ်ိဳးေတြမွာ ၊ အထဲက စာေတြ လိုက္ဖ်က္ရရင္လည္း မလြယ္ဘူး။ File ကိုဖ်က္ျပစ္လိုက္ျပီး ၊ process က log ျပန္လာေရးခိုင္းတာကလည္း ေျပာရင္ သိပ္မေကာင္းဖူး။ File ကို ဖ်က္ျပစ္လိုက္ရတာကိုက မေကာင္းဘူး။ အထဲက content ကိုပဲ ရွင္းလိုက္ခ်င္ရင္ ဒီလိုေလးက လြယ္တယ္ ။
> /path/to/log.file

အေရွ႕က '>' ေလးက command ထဲမွာပါပါတယ္။ တစ္ကယ္က
echo "" > /path/to/log.file

ကိုလုပ္သြားတာပါ။ echo command နဲ႕ output pipe '>' ကိုသိရင္ ဒါကိုသိပါလိမ့္မယ္။ File ထဲက content ကို blank space တစ္ခုနဲ႕ overwrite လုပ္လိုက္တာပါ။ အဲေတာ့ log file က empty log ျဖစ္သြားတာေပါ့။

..........
ေနာက္တစ္ခုကေတာ့ shell arguments ေတြပါ။ အသုံးျဖစ္ဆုံးကေတာ့ ! နဲ႕ !$ ပါ ။
! က ေနာက္ဆုံးသုံးခဲ့တယ့္ argument ကို ကိုယ္စားျပဳပါတယ္။ တကယ္လို႕ အေပၚမွာ file တစ္ခုကို vi သုံးျပီး edit ထားတယ္။ အခု တျခား directory ကိုေရာက္ေနျပီ ။ File path ၾကီးကရွည္လို႕ ျပန္မ႐ိုက္ခ်င္ဖူးဆိုရင္
!vi

လို႕ သုံးလို႕ရပါတယ္။ Shell history ထဲက ေနာက္ဆုံး vi command ကိုျပန္ေခၚေပးပါလိမ့္မယ္။

.......
!$ ကေတာ့ last command ရဲ့ argument ကိုပဲယူတာပါ။
ls -l /bar/nyar/thar/da/kar/file

လို႕ ရွာျပီး၊ ေနာက္တစ္လိုင္းမွာ အဲ file ကို vi မွာ edit ဖို႕ဆိုရင္ ပံုမွန္ဆို vi /bar/nyar/thar/da/kar/file ဆိုျပီး ရွည္ရွည္လွ်ားလွ်ား႐ိုက္ေနရပါမယ္။ အဲေတာ့
vi !$

လို႕႐ိုက္လိုက္ရင္ ေနာက္ဆုံး command ရဲ့ argument ကိုျပန္ယူျပီး vi သြားပါလိမ့္မယ္ ။
( Up arrow နဲ႕ last command ကိုျပန္ေခၚ၊ Home ကိုႏွိပ္ျပီး ls -l ကိုဖ်က္ vi လို႕႐ိုက္ ၊ ဒါလည္းရပါတယ္။ ဒါေပမယ့္ ပိုမရွည္ဖူးလား။ ဒါေတာင္ Home တို႕ End တို႕ကို Shell environment ထဲမွာ set ထားမွပါ။ Unix အမ်ားစုမွာ default အားျဖင့္မပါပါဘူး။ Home ႏွိပ္လိုက္ရင္ ^ ေတြနဲ႕ ေပၚလာပါလိမ့္မယ္။ )

..........
အခုေတာ့ ေတာ္ေလာက္ျပီ။ အခုသုံးလိုက္မိတာေလးေတြ ေျပာျပတာပါ။ ေနာက္ၾကံုရင္ ၾကံုတာေတြ ေရးပါအုန္းမယ္ ။ တစ္ခ်ိဳ႕ command ေတြက သူ႕ေနာက္က option ေတြအရမ္း powerful ျဖစ္တာေတြရွိပါတယ္။ find တို႕လို command မ်ိဳးေပါ့။ exec လို အသုံးတယ့္တာေတြလည္း ရွိပါေသးတယ္။ ေနာက္မ်ားမွ ....

Divinity