วันอังคารที่ 12 เมษายน พ.ศ. 2554

คำสั่งขั้นสูง LINUX และ UNIX (Linux ตอนที่2)

1.1 คำสั่ง ls : ใช้แสดงรายชื่อแฟ้มทั้งหมดใน home directory

--------------------------------------------------------------------------------
ทุกท่านที่มี account ใน linux จะมี home directory ของตนเอง เพื่อใช้เก็บแฟ้มต่าง ๆ ภายใต้ระบบ
linux เมื่อต้องการทราบว่ามีแฟ้มอะไรที่เก็บไว้บ้าง สามารถใช้คำสั่ง ls ได้ และสามารถกำหนด parameter ได้หลายตัว เช่น -al --sort เป็นต้น
ตัวอย่างคำสั่ง และการใช้งาน


ls -alt :: เพื่อแสดงรายชื่อแฟ้มทั้งหมด และจัดเรียงตามเวลา ให้ลองลบอักษรออกทีละตัวจาก alt ดูนะครับ
ls -alt | more :: เพื่อแสดงรายชื่อแฟ้มทั้งหมด แต่หยุดทีละหน้า เมื่อมีจำนวนแฟ้มเกินที่จะแสดงได้ ใน 1 หน้า
ls -al --sort=time | more :: แสดงรายชื่อแฟ้มเรียงตามเวลา แยกทีละหน้า โดยละเอียด
ls -R | more :: แสดงรายชื่อในทุก directory ในห้องปัจจุบัน
ถ้าสังเกตนะครับ แฟ้มที่มี . หน้าชื่อแฟ้ม จะหมายถึงแฟ้มที่ซ่อนไว้ ถ้าใช้คำสั่ง ls หรือ ls -l จะไม่เห็นแฟ้มเหล่านี้
ถ้ามีอักษร D ที่ Column แรก ในตอนแสดงชื่อแฟ้ม ด้วยคำสั่ง ls -al ก็จะหมายถึง directory ไม่ใช่แฟ้มธรรมดา

--------------------------------------------------------------------------------
1.2 คำสั่ง chmod : ใช้เปลี่ยนสิทธิ์ของแฟ้ม เจ้าของ(Owner), คนในกลุ่ม(Group), คนอื่น(Other) สามารถทำอะไรได้บ้าง
--------------------------------------------------------------------------------
เมื่อใช้คำสั่ง ls ท่านจะเห็นตัวอักษร RWXRWXRWX หรือทำนองนี้หน้าชื่อแฟ้ม ซึ่งเป็นการกำหนด
สิทธิ์ของแต่ละแฟ้ม ว่า อ่านได้ เขียนได้ และประมวลผลได้ โดยแยกเป็นส่วนของ เจ้าของ กลุ่ม คนอื่น
ซึ่งเป็นคำสั่งที่จำเป็นมากสำหรับ webmaster ในการดูแลระบบ และท่านที่ต้องการเขียน CGI
จะต้องรู้คำสั่งนี้ เพราะ เมื่อส่งแฟ้ม CGI เข้าไปใน server และต้องการให้คนทั่วไปเข้ามาใช้บริการ
โปรแกรมของตนที่เขียนขึ้นด้วย Perl จะไม่สามารถใช้ได้ ถ้าไม่กำหนดให้คนอื่น สามารถประมวลผลได้ (x)
จึงจำเป็นต้องใช้คำสั่ง เช่น chmod 755 hello.pl หรือ chmod 775 fileforyou.pl หรือ chmod +x test.pl เป็นต้น ในแต่ละกลุ่มจะมีการกำหนดสิทธิได้ 3 แบบ
ตัวอักษร R มาจาก Read หมายถึง อ่าน
ตัวอักษร W มาจาก Write หมายถึง เขียน
ตัวอักษร X มาจาก Execute หมายถึง ประมวลผล
ตัวอย่างเช่น
--- : ไม่มีสิทธิอะไรเลย (เลขที่ใช้คือ 0)
--X : ประมวลผลได้อย่างเดียว (เลขที่ใช้คือ 1)
R-- : อ่านได้อย่างเดียว (เลขที่ใช้คือ 4)
RW- : อ่าน และเขียนได้ (เลขที่ใช้คือ 6)
R-X : อ่าน และประมวลผลได้ (เลขที่ใช้คือ 5)
RWX : อ่าน เขียน และประมวลผลได้ (เลขที่ใช้คือ 7) ความหมายของ RWXRWXRWX จะเห็นว่ามีอักษร 9 ตัว
3 ตัวแรกหมายถึง เจ้าของ
3 ตัวที่สองหมายถึง กลุ่ม
3 ตัวที่สามหมายถึง คนอื่น
ตัวอย่างเช่น
RWX------ : เจ้าของเท่านั้นที่มีสิทธิทุกอย่าง (เลขที่ใช้คือ 700)
RWXRWX--- : เจ้าของ และสามาชิกกลุ่มเดียวกันมีสิทธิทุกอย่าง (เลขที่ใช้คือ 770)
RWXR-XR-X : เจ้าของทำได้หมด ส่วนกลุ่มและคนอื่นอ่านและประมวลผลได้ (เลขที่ใช้คือ 755)
R--R--R-- : ทุกคนอ่านได้อย่างเดียว (เลขที่ใช้คือ 444)

ตัวอย่างคำสั่ง และการใช้งาน
chmod 777 index.php :: ทำให้แฟ้มนี้ อ่าน เขียน และประมวลผล โดยทั้ง 3 กลุ่ม
chmod 755 * -Rf :: ทำให้ทุกแฟ้ม ทุก direcroty ในห้องปัจจุบัน เปลี่ยนตามที่กำหนด

--------------------------------------------------------------------------------
1.3 คำสั่ง man : เป็นคำสั่งที่สำคัญมาก เพราะจะช่วยให้อธิบายคำสั่งต่าง ๆ ให้ท่านได้ (Manual)
--------------------------------------------------------------------------------
ผมเชื่อว่าทุกคนที่ใช้ unix หรือ linux ต้องเคยใช้คำสั่งนี้มาก่อน เพราะจะเป็นคำสั่งที่ช่วยอธิบายหน้าที่ของคำสั่ง
พร้อมกับแสดง parameter ที่สามารถใช้ได้ทั้งหมดของคำสั่งนั้น และยังมีตัวอย่างการใช้ และคำสั่งที่เกี่ยวข้องอีก
ทำให้ประหยัดเวลาในการค้นเอกสารได้อย่างมาก บางท่านอาจศึกษา linux ด้วยการอ่านจาก man
อย่างเดียวเลยก็มีนะครับ โดยไม่ต้องไปหาซื้อหนังสือที่ไหนมาอ่านก็ทำได้
ตัวอย่างคำสั่ง และการใช้งาน
man man :: เพื่ออธิบายคำสั่ง man เอง ว่าตัวคำสั่งนี้ใช้อย่างไร
man ls :: เพื่ออธิบายคำสั่ง ls ว่าใช้อย่างไร
man useradd :: เพื่ออธิบายคำสั่ง useradd ว่าใช้อย่างไร

--------------------------------------------------------------------------------
1.4 คำสั่ง mkdir, rmdir, cd : งานต่าง ๆ เกี่ยวกับ directory
--------------------------------------------------------------------------------
ผู้ใช้คอมพิวเตอร์ที่ใช้ dos มาก่อนต้องคุ้นเคยกับ directory แน่นอน สำหรับคำสั่งเกี่ยวกับ directory
ในที่นี้มี 3 คำสั่ง mkdir หมายถึง สร้าง directory (Make directory) rm หมายถึง ลบ directory
(Remove directory) และคำสั่งนี้ยังใช้ลบแฟ้มตามปกติได้อีกด้วย cd หมายถึงเปลี่ยน directory (Change directory)
ตัวอย่างคำสั่ง และการใช้งาน
mkdir hello :: สร้าง directory ชื่อ hello ในห้องปัจจุบัน
rmdir hello.htm :: จะลบแฟ้มชื่อ hello.htm
cd / :: ย้าย directory ไปยัง root หรือห้องนอกสุด
cd .. :: ย้าย directory ออกไปข้างบน 1 ระดับ
cd ~/x :: เข้าไปยังห้อง x ของ home directory เช่น /home/thaiall/x ถ้า home directory คือ /home/thaiall

--------------------------------------------------------------------------------
1.5 โปรแกรม pico : เป็น editor ที่ใช้สำหรับแก้ไขแฟ้มแบบ text คล้าย vi แต่มีประสิทธิภาพกว่ามาก
--------------------------------------------------------------------------------
เพียงแต่พิมพ์คำว่า pico แล้ว enter ก็ใช้งานได้เลย การจะจัดเก็บ หรืองานต่าง ๆ ที่มีบริการไว้มากมาย
ท่านสามารถอ่านได้จากเมนูด้านล่าง ซึ่งเครือ่งหมาย ^ หมายถึงการกดปุ่ม Ctrl ประกอบอักษรต่าง ๆ นั่นเอง
ผมคิดว่าท่านน่าจะพออ่านรู้เรื่อง หรือจะพิมพ์ว่า pico xx ก็จะเป็นการสร้างแฟ้มชื่อ xx ให้ทันที แต่หากมีแล้ว
ก็จะเปิดแฟ้ม xx มาให้แก้ไขในโปรแกรม xx เมื่อท่านต้องการเลิกก็ทำได้โดยกดปุ่ม Ctrl-X เป็นอันเรียบร้อย
หากท่านใดเคยใช้ vi เมื่อลองใช้โปรแกรมนี้จะติดใจอย่างแน่นอน เพราะใช้งานได้ง่ายกว่า หลายเท่านัก หลายครั้ง
ที่พิมพ์คำว่า pico แล้วไม่มีในเครื่อง ก็เพราะไม่ได้ลงโปรแกรม pine เมื่อต้องการใช้ pico ก็ต้องติดตั้งโปรแกรม
pine เข้าไปในเครื่อง จากแผ่น CD ด้วยคำสั่ง rpm -i pine*
--------------------------------------------------------------------------------
1.6 โปรแกรม emacs : เป็น editor ที่ใช้สำหรับแก้ไขแฟ้มแบบ text คล้าย vi แต่มีประสิทธิภาพกว่ามาก
--------------------------------------------------------------------------------
ทำงานได้คล้าย ๆ กับ pico แต่หลายคนบอกว่า ตัวนี้ทำงานได้ดีกว่า แต่ผมว่า pico ใช้งานได้ง่ายกว่ากันเยอะเลย
เพราะเห็นเมนูด้านล่าง แต่ของ emacs จะใช้ ctrl-h ดูส่วนช่วยเหลือ และกด ctrl-x + ctrl-c จึงจะออกจากโปรแกรม
อาจเป็นเพราะผมใช้ไม่ชำนาญมังครับ ในเมื่อผมใช้ pico เป็น editor ผมคงไม่จำเป็นต้องศึกษา emacs เพิ่มเติมแล้ว
ยกเว้นว่าสักวันอาจมีเหตุจำเป็นที่ความสามารถของ pico ให้ไม่ได้ แต่ emacs ให้ได้ก็เป็นได้
Welcome to GNU Emacs, one component of a Linux-based GNU system.
Get help C-h (Hold down CTRL and press h)
Undo changes C-x u Exit Emacs C-x C-c
Get a tutorial C-h t Use Info to read docs C-h i
Ordering manuals C-h RET
Activate menubar F10 or ESC ` or M-`
(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
If you have no Meta key, you may instead type ESC followed by the character.)


--------------------------------------------------------------------------------
1.7 โปรแกรม vi : เป็น editor ที่ใช้สำหรับแก้ไขแฟ้มแบบ text
--------------------------------------------------------------------------------
Text editor ที่ใช้งานได้ยาก แต่มีใน linux ทุกรุ่น ในบางเครื่องไม่มี pico เพราะไม่ได้ติดตั้ง mail หรือ pine จึงจำเป็นต้องใช้โปรแกรม vi สำหรับแก้ไขข้อมูลในแฟ้มต่าง ๆ ของ linux เช่นการใช้คำสั่ง man ก็คือการใช้ความสามารถของ vi ในการนำข้อมูลมาแสดงผลนั่นเอง
ตัวอย่างคำสั่ง และการใช้งาน
esc กลับไปยังโหมดคำสั่ง
enter ย้ายไปยังต้นบรรทัดของบรรทัดถัดไป
i ใส่ข้อความก่อนเคอร์เซอร์
a ใส่ข้อความหลังเคอร์เซอร์
A ใส่ข้อความที่ท้ายบรรทัดปัจจุบัน
dd ลบบรรทัดปัจจุบันทั้งบรรทัด
x ลบอักษร 1 ตัวอักษร
cw เปลี่ยนข้อความ
:w บันทึกแฟ้ม
:q! ออกโดยไม่ เปลี่ยนแปลงใด ๆ
:wq บันทึกแฟ้ม และออกจากโปรแกรม vi


--------------------------------------------------------------------------------
1.8 คำสั่ง id, finger, who, w : ทุกคำสั่งข้างต้นใช้สำหรับตรวจสอบผู้ใช้ แต่จะให้รายละเอียดต่างกันไป
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
id uname :: ใช้ตรวจดูว่ามี account uname นี้ในระบบหรือไม่ ให้ผลสั้น
finger uname :: ใช้ตรวจดูว่ามี account uname นี้ในระบบหรือไม่ ให้ผลละเอียด ทั้ง last login หรือ email ฉบับล่าสุด
finger @www.isinthai.com :: ใช้แสดงรายชื่อทุกคนในระบบที่กำลัง login อยู่ในระบบ ใช้ได้กับทุกระบบที่ไม่ปิดบริการนี้
who |grep thai :: ใช้แสดงรายชื่อทุกคนในระบบ แต่ใช้นอกระบบตนเองไม่ได้ และเลือกเฉพาะบรรทัดที่มีอักษร thai
w :: ใช้แสดงรายชื่อทุกคนในระบบ แต่ใช้นอกระบบตนเองไม่ได้

--------------------------------------------------------------------------------
1.9 คำสั่ง cat : แสดงข้อมูลในแฟ้ม คล้ายคำสั่ง type ในระบบ DOS
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
cat /etc/passwd :: แสดงข้อมูลในแฟ้ม /etc/passwd
cat /etc/passwd | more :: แสดงข้อมูลในแฟ้ม /etc/passwd ทีละหน้า
ตัวอย่างข้อมูลในแฟ้ม passwd suwit:x:500:500:Suwit:/home/suwit:/bin/bash prasert:x:501:501::
/home/prasert:/bin/bash bcom101:x:502:502::/home/bcom302:/bin/bash

--------------------------------------------------------------------------------
1.10 คำสั่ง ifconfig : แสดงข้อมูลเกี่ยวกับ Network interface และแสดง ip ต่าง ๆ ที่มีการเพิ่มเข้าไปใน server ได้
--------------------------------------------------------------------------------

ดูผลการทำงานของคำสั่ง ifconfig
eth0 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.12 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:673054 errors:0 dropped:0 overruns:0 frame:0
TX packets:666268 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:74892865 (71.4 Mb) TX bytes:680121131 (648.6 Mb)
Interrupt:9 Base address:0xcf00
eth0:1 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.1 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:9 Base address:0xcf00

เพิ่ม ip ใหม่อีก 1 ip เช่น #/sbin/ifconfig eth0:1 202.29.78.1
สามารถดูวิธีเพิ่มหลาย IP ในคอมพิวเตอร์เครื่องเดียว ได้จากหัวข้อ 9.10 ด้วยการแก้ไขแฟ้ม /etc/rc.d/rc.local

--------------------------------------------------------------------------------
1.11 คำสั่ง netstat : แสดงสถานะของเครือข่ายว่ามีโปรแกรมใดเปิดให้บริการ
--------------------------------------------------------------------------------

ดูผลการทำงานของคำสั่ง netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:smtp *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 www.isinthai.com:ssh 202.29.78.200:1225 ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 855 /var/lib/mysql/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 119 /dev/log
unix 2 [ ] STREAM CONNECTED 3007
unix 2 [ ] STREAM CONNECTED 859


--------------------------------------------------------------------------------
1.12 คำสั่ง service : ดูสถานะของบริการต่าง ๆ ว่าถูกเปิดหรือ running อยู่หรือไม่
--------------------------------------------------------------------------------

ดูผลการทำงานของคำสั่ง service --status-all
httpd (pid 2160 2159 2158 2155 2114 583 579 578 577 576 575 573) is running...
mysqld (pid 446 429 427 414) is running...
sendmail (pid 1700 1690) is running...
sshd (pid 2970 358) is running...
xinetd (pid 3923 369) is running...


--------------------------------------------------------------------------------
1.13 คำสั่ง xinetd : ดูบริการภายใน xinetd ว่าอะไรเปิดอยู่บ้าง ทำให้เข้าไปเปิดที่ห้อง /etc/xinetd.d
แล้วเลือกเปิดบริการเฉพาะที่ต้องการ เช่นแก้แฟ้ม talk เพื่อให้เปิดบริการ talk ใน server เป็นต้น
--------------------------------------------------------------------------------

ดูผลบางส่วนจากการทำงานของคำสั่ง xinetd -d
Service configuration: ftp
id = ftp
flags = IPv4
socket_type = stream
Protocol (name,number) = (tcp,6)
Nice = 10
Groups = no
Bind = All addresses.
Server = /usr/sbin/vsftpd
Server argv = vsftpd
Only from: All sites
No access: No blocked sites
Logging to syslog. Facility = authpriv, level = info
Log_on_success flags = HOST PID
Log_on_failure flags = HOST


--------------------------------------------------------------------------------
1.14 คำสั่ง whereis : ค้นหาแฟ้มที่ต้องการว่าอยู่ที่ห้องใด แต่ค้นได้เฉพาะที่กำหนดไว้ใน PATH เท่านั้น หากต้องการค้นทั้งเครื่องต้องใช้คำสั่ง find
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
whereis usermod :: แสดงห้องที่เก็บคำสั่ง usermod ทำให้สามารถสั่ง run จากห้องที่เก็บคำสั่งโดยตรงได้
whereis ifconfig :: แสดงห้องที่เก็บคำสั่ง ifconfig ทำให้ใช้คำสั่งเช่น /sbin/ifconfig ได้โดยตรง

--------------------------------------------------------------------------------
1.15 คำสั่ง cp, rm, mv : จัดการแฟ้มเช่น คัดลอก ลบ และย้าย
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
cp x y :: เดิมมีแฟ้มชื่อ x ต้องการแฟ้ม y ที่เหมือน x ขึ้นมาใหม่ สามารถใช้คำสั่ง cp
rm y :: ลบแฟ้ม y ออกจากเครื่อง ซึ่งอยู่ใน directory ปัจจุบัน
rm -r directoryname :: จะลบ directory ในเครื่อง sun และแฟ้มทั้งหมดใน directory นั้น และการลบแฟ้ม จะมีการถาม confirm ทุกแฟ้มเสมอ
rm -rf directoryname :: จะลบ directory ใช้ใน Redhat และแฟ้มทั้งหมดใน directory นั้น และการลบแฟ้ม จะมีการถาม confirm ทุกแฟ้มเสมอ
rm -f * :: ลบแฟ้มทั้งหมดโดยไม่ถาม yes
mv x /root :: ย้ายแฟ้ม x จากห้องปัจจุบันไปไว้ในห้อง /root

--------------------------------------------------------------------------------
1.16 คำสั่ง ping : ตรวจสอบ ip ของเครื่องเป้าหมาย และการเชื่อมต่อ internet
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
ping www.thaiall.com :: ตัวสอบการมีอยู่ของ www.thaiall.com และแสดงเลข IP ของเว็บนี้
ping 202.29.78.100 -c 5 :: แสดงผลการทดสอบเพียง 5 บรรทัด
ping 202.29.78.2 :: ผลดังข้างล่างนี้ แสดงว่าไม่พบเครื่องที่มีเลข ip ดังกล่าว PING 202.29.78.2 (202.29.78.2)
from 202.29.78.12 : 56(84) bytes of data. From 202.29.78.12 icmp_seq=1
Destination Host Unreachable From 202.29.78.12 icmp_seq=2 Destination
Host Unreachable From 202.29.78.12 icmp_seq=3 Destination Host Unreachable

--------------------------------------------------------------------------------
1.17 คำสั่ง env : แสดงค่า environment ปัจจุบัน
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
env

HISTSIZE=1000
SSH_CLIENT=202.29.78.100 1091 22
OLDPWD=/usr/sbin
QTDIR=/usr/lib/qt3-gcc3.2
SSH_TTY=/dev/pts/0
USER=burin
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;.... :
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
MAIL=/var/spool/mail/burin
PWD=/etc
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
HOME=/root
SHLVL=2
LOGNAME=burin
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env

--------------------------------------------------------------------------------
1.18 คำสั่ง lynx : Text browser ที่ใช้งานง่าย ใช้ดู source หรือ download ได้
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
lynx www.thaiall.com :: เพื่อเปิดเว็บ www.thaiall.com แบบ text mode
lynx http://www.yonok.ac.th :: เพื่อเปิดเว็บ www.yonok.ac.th แบบ text mode
lynx -dump http://www.yonok.ac.th :: เพื่อแสดงผลลัพธ์แบบไม่ interactive คือการ view ผลแล้วหยุดทันที
lynx -dump -width=500 http://piology.org/.procmailrc.html|grep '^|'|cut -c3- :: ตัวอย่างการนำไปใช้

--------------------------------------------------------------------------------
1.19 คำสั่ง nslookup : แสดงข้อมูลเกี่ยวกับ name server จาก ip หรือ domain name
--------------------------------------------------------------------------------

คำสั่งนี้ ถูกประกาศว่าต่อไปอาจไม่พบใน Redhat รุ่นใหม่ ถ้าต้องการใช้คำสั่งแบบนี้สามารถใช้ dig หรือ host แทนได้ เช่น host yn1.yonok.ac.th หรือ dig yn1.yonok.ac.th เมื่อเข้าไปใน nslookup สามารถออกมาได้ด้วยการพิมพ์คำสั่ง exit หลังเครื่องหมาย >
ตัวอย่างคำสั่ง และการใช้งาน
nslookup 202.28.18.65
Non-authoritative answer:
65.18.28.202.in-addr.arpa name = mars.uni.net.th.
Authoritative answers can be found from:
18.28.202.in-addr.arpa nameserver = mars.uni.net.th.
18.28.202.in-addr.arpa nameserver = ns.netserv.chula.ac.th.
mars.uni.net.th internet address = 202.28.18.65
nslookup www.thaiall.com
Name: www.thaiall.com
Address: 66.150.1.141


--------------------------------------------------------------------------------
1.20 คำสั่ง tail : แสดงส่วนท้ายของแฟ้มที่มีขนาดใหญ่ ต้องข้ามกับ cat ที่ดูตั้งแต่เริ่มแฟ้ม
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
tail index.html :: ดูส่วนท้ายของแฟ้ม index.html ใน Current directory
tail --lines=5 /var/log/messages :: ดูส่วนท้ายของแฟ้ม /var/log/messages แต่ต้องเป็น root จึงจะดูได้
tail /var/log/html/access.log :: ดูส่วนท้ายเพียง 10 บรรทัด ซึ่งเป็นค่า default ที่ไม่ได้กำหนดจำนวนบรรทัด
tail --lines=100 /var/log/html/access_log > access_bak :: เป็นการ backup ในขั้นแรก ก่อนใช้ mv ย้ายไปทับแฟ้มเดิม

--------------------------------------------------------------------------------
1.21 คำสั่ง telnet : ใช้ติดต่อเข้า server ต่าง ๆ ตาม port ที่ต้องการ แต่ปัจจุบัน server ต่าง ๆ ปิดบริการ telnet แต่เปิด SSH แทน
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
telnet 202.202.202.202 :: ขอติดต่อเข้าเครื่อง 202.202.202.202 การไม่กำหนด port คือเข้า port 23
telnet www.school.net.th 21 :: ขอติดต่อผ่าน port 21 ซึ่งเป็น FTP port
telnet mail.loxinfo.co.th 25 :: ตรวจ smtp ว่าตอบสนองกลับมา หรือไม่
telnet class.yonok.ac.th 110 :: ทดสอบ pop service ของ windows server 2003 Microsoft Windows POP3 Service Version 1.0 ready. USER aa@class.yonok.ac.th +OK PASS xxxxxxx +OK User successfully logged on

--------------------------------------------------------------------------------
2.1 คำสั่ง df : แสดงการเนื้อที่ใช้งานทั้งหมดของ Harddisk ว่าเหลือเท่าใด
--------------------------------------------------------------------------------
ช่วยให้ผู้ดูแลระบบรู้ว่าตอนนี้เนื้อที่ใน Harddisk เหลืออยู่เท่าใด และอาจใช้ตรวจสอบได้ว่า มีใครแอบมา upload แฟ้มขนาดใหญ่ไว้หรือไม่ จะได้ตรวจสอบในรายละเอียดของแต่ละ user ต่อไป (ผมเองก็ใช้บ่อย เพราะถ้า server เล็ก ๆ จะเต็มบ่อยครับ ต้องคอย clear เสมอ)
ตัวอย่างคำสั่ง และการใช้งาน
df :: เพื่อแสดงรายงานสรุปการใช้ในแต่ละส่วน
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 505605 82764 396737 18% /
/dev/hda1 101089 9180 86690 10% /boot
/dev/hda3 1423096 41956 1308848 4% /home
none 30740 0 30740 0% /dev/shm
/dev/hda2 3889924 1551872 2140456 43% /usr
/dev/hda6 1027768 952876 22684 98% /var

--------------------------------------------------------------------------------
2.2 คำสั่ง du : แสดงการเนื้อที่ใช้งาน ของแต่ละ directory โดยละเอียด
--------------------------------------------------------------------------------
ช่วยให้ผู้ดูแลระบบรู้ว่า directory ใด ใช้เนื้อที่ใด หรือใช้ดูรวม ๆ ว่า ผู้ใช้แต่ละคนใช้เนื้อที่เก็บข้อมูลกันเท่าใด เพราะผู้ใช้ปกติจะใช้กันไม่เยอะ แต่ถ้าตรวจสอบแล้วเยอะผิดปกติ ก็จะเข้าไปดูว่า เยอะเพราะอะไร จะได้แก้ไขได้
ตัวอย่างคำสั่ง และการใช้งาน
du :: เพื่อแสดงรายชื่อ directory และเนื้อที่ที่ใช้ไป
du -all :: เพื่อแสดงโดยละเอียดว่าแต่ละแฟ้มมีขนาดเท่าใด ใน directory ปัจจุบัน
du | sort -g :: แสดงการใช้พื้นที่ของแต่ละ directory พร้อม sort จากน้อยไปมาก มีหน่วยเป็น Kb
du -b :: แสดงหน่วยเป็น byte ของแต่ละ directory

--------------------------------------------------------------------------------
2.3 คำสั่ง ps : แสดง Process หรือโปรแกรมที่ประมวลผลอยู่ในระบบขณะนั้น
--------------------------------------------------------------------------------
ช่วยให้ผู้ดูแลระบบ ติดตามได้ว่ามีโปรแกรมอะไรที่ไม่ถูกต้อง run อยู่ หรือโปรแกรมอะไร ที่ผู้ศึกษาลองประมวลผลแล้วค้างอยู่ จะได้ทำการแก้ไง มิฉนั้นระบบก็จะทำงานค้าง เพราะโปรแกรมที่ไม่ควรอยู่ในระบบ กำลังประมวลผลโดยไม่จำเป็น โดยเฉพาะพวก bot จะทำให้ server ล่มง่ายมาก
ตัวอย่างคำสั่ง และการใช้งาน
ps :: แสดงชื่อ process ต่าง ๆ ที่ทำงานอยู่อย่างสั้น
ps -ef :: แสดงข้อมูลของ process โดยละเอียด
ps -ax :: แสดงข้อมูลของ process พร้อมชื่อโปรแกรมได้ละเอียด
ps -aux :: แสดงข้อมูลของ process พร้อมชื่อโปรแกรม และชื่อผู้สั่งได้ละเอียดมาก

--------------------------------------------------------------------------------
2.4 คำสั่ง kill : เมื่อทราบว่า process ใดที่มีปัญหา ก็จะเห็นเลขประจำ process คำสั่ง kill จะสามารถ process ออกจากระบบได้
--------------------------------------------------------------------------------
ช่วยยกเลิก process ที่ไม่ถูกต้องออกจากระบบ ถ้าขณะนั้นผู้ใช้คนหนึ่งกำลังใช้งานอยู่ หาก process หลักของเขาถูก kill จะทำให้ผู้ใช้ท่านนั้น หลุดออกจากระบบทันที (สำหรับคำสั่งนี้จะถูกใช้โดย super user เท่านั้น ผู้ใช้ธรรมดาไม่มีสิทธิ์)
ตัวอย่างคำสั่ง และการใช้งาน
kill -9 เลขประจำprocess :: เลขประจำ process ท่านจะได้จากการใช้ ps -ef อยู่แล้ว
kill -9 1255 :: ลบ process ที่ 1255 ออกจากระบบไป

--------------------------------------------------------------------------------
2.5 คำสั่ง find : เมื่อไฟล์ที่ต้องการว่าอยู่ใน directory ของเครื่องเราหรือไม่
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
find / -name hello.pl :: ใช้ค้นหาแฟ้ม hello.pl ในทุก directory
find / -name hello* :: ใช้ค้นหาแฟ้มที่ขึ้นต้นด้วยคำว่า hello
find /bin -size 626188c :: ใช้ค้นหาแฟ้มที่มีขนาด 626188 ถ้าเป็น RH8 จะพบแฟ้ม bash

--------------------------------------------------------------------------------
2.6 คำสั่ง gzip : ใช้สำหรับแตกแฟ้มที่ถูกบีบอัด แล้วนามสกุล gz หรือ z แต่ทั่วไปเขาแนะนำให้ใช้ tar สำหรับสกุล .tar.gz
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
gzip -d x.tar.gz :: ใช้แตกแฟ้มที่นามสกุล gz
man gzip :: ใช้ดูว่า gzip ใช้งานอะไรได้บ้าง
gzip -d radius-1.16.1.tar.Z :: ได้แฟ้มนี้จาก ftp.livingston.com/pub/le/radius/ เป็นระบบรับโทรศัพท์เข้าเครือข่าย
gzip -dc x.tar.Z|tar xvf - :: ประหยัดขั้นตอนในการใช้คำสั่ง 2 ครั้ง เพราะคำสั่งชุดนี้จะใช้ทั้ง gzip และ tar กับ x.tar.z ได้ตามลำดับ

--------------------------------------------------------------------------------
2.7 คำสั่ง tar : ใช้สำหรับแตกแฟ้มที่ถูกบีบอัด แล้วนามสกุล tar
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
tar xvf x.tar :: ใช้สำหรับแตกแฟ้มที่นามสกุล tar ปกติแล้วจะมีการสร้าง directory ของแฟ้มพร้อมโปรแกรมอีกเพียบ
tar xvfz squid-2.3-200103110000-src.tar.gz :: จะคลาย gz พร้อมกับใช้คำสั่ง tar ได้พร้อม ๆ กัน ไม่ต้องใช้ gzip และมาใช้ tar
man tar :: ใช้ดูว่า tar ใช้งานอะไรได้บ้าง
tar zcvf abc.tar.gz /etc :: ใช้ copy /etc เก็บเป็นแฟ้ม abc.tar.gz แบบบีบอัด
tar zxvf abc.tar.gz :: ใช้คลายแฟ้ม abc.tar.gz ซึ่งจะได้ directory /etc ออกมาทั้งหมด

--------------------------------------------------------------------------------
2.8 คำสั่ง last : ใช้แสดงรายชื่อผู้ login เข้ามาล่าสุด
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
last |grep reboot :: ใช้ดูระบบถูก reboot เมื่อใดบ้าง
last |more :: ใช้รายชื่อผู้ login เข้ามาในระบบล่าสุดทีละหน้า

--------------------------------------------------------------------------------
2.9 คำสั่ง grep : ใช้สำหรับเลือกข้อมูลเฉพาะบรรทัดที่ต้องการ
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
more /etc/passwd|grep thaiall :: ใช้แสดงข้อมูลในแฟ้ม /etc/passwd แต่เลือกเฉพาะบรรทัดที่มีคำว่า thaiall
rpm -qa|grep ftp :: ใช้ดูว่าระบบลงโปรแกรม ftp หรือยัง เวอร์ชั่นใดบ้าง
last |grep reboot :: ใช้ดูระบบถูก reboot เมื่อใดบ้าง

--------------------------------------------------------------------------------
2.10 คำสั่ง date : ใช้ดูวันที่ หรือเปลี่ยนวันที่ และเวลาได้ date [OPTION] [MMDDhhmm[[CC]YY][.ss]]
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
date +%x :: ดูวันที่ปัจจุบัน เช่นการแสดงเลข 04/27/01 ออกมา
date +%d :: ดูวันที่ปัจจุบัน เช่นการแสดงเลข 27 ออกมา
date 04271340 :: กำหนดวันที่ใหม่ให้เป็น วันที่ 27 เดือน 4 เวลา 13.40 น. (mmddhhmmccyy)
hwclock --systohc :: เมื่อเปลี่ยนเวลาด้วย date หาก restart เครื่องเวลาจะผิดเหมือนเดิมต้องใช้คำสั่งนี้ เพื่อเขียนเวลาลงไปใน hardware clock จึงจะเปลี่ยนเวลา hardware ได้

--------------------------------------------------------------------------------
2.11 คำสั่ง top : ใช้แสดงสถานะการใช้ทรัพยากร ภายในเครื่อง
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
top :: แสดงการใช้ทรัพยากรของเครื่อง จากแต่ละ process ทดสอบคำสั่งนี้ใน Redhat 8.0
ตัวอย่างผลของการใช้คำสั่ง
CPU states: 0.5% user, 1.3% system, 0.0% nice, 98.0% idle
Mem: 31328K av, 28872K used, 2456K free, 0K shrd, 1032K buff
Swap: 1718912K av, 2608K used, 1716304K free 16528K cached

PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
18306 root 14 0 852 852 672 R 0 1.5 2.7 0:00 top
18229 root 1 0 1684 1536 1240 S 0 0.3 4.9 0:00 sshd
1 root 0 0 160 116 92 S 0 0.0 0.3 0:08 init
2 root 0 0 0 0 0 SW 0 0.0 0.0 0:01 kflushd


--------------------------------------------------------------------------------
2.12 คำสั่ง ntsysv หรือ setup : ใช้เปิด-ปิด บริการของเครื่องที่สะดวกรวดเร็ว
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
setup :: แสดงการตัวเลือกให้กำหนดบริการต่าง ๆ ปกติจะเลือก system services บริการที่เปิดใน server ของผมประกอบด้วย httpd, imap, ipop3, iptables, named, network, sendmail, servers, services, vsftpd, xinetd เพื่อให้บริการ web, mail, ftp และ dns
ntsysv :: ใช้เปิด-ปิดบริการ ให้ผลเหมือน setup, services (แต่คำสั่งนี้ถูกยกเลิกใน RH รุ่นใหม่)

--------------------------------------------------------------------------------
2.13 คำสั่ง route : ใช้เส้นทางการเชื่อมเครือข่าย
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
# route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
202.29.78.0 * 255.255.255.0 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default 202.29.78.254 0.0.0.0 UG 0 0 0 eth0


--------------------------------------------------------------------------------
2.14 คำสั่ง shutdown, reboot : ใช้ปิดเครื่อง หรือ ปิดและเปิดเครื่องใหม่อย่างถูกวิธี
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
shutdown -h now หรือ halt :: สั่งปิดเครื่องทันที (แต่ใช้เวลาประมาณ 1 นาทีเพื่อปิดบริการต่าง ๆ)
reboot หรือ shutdown -r now :: ปิด และเปิดเครื่องใหม่ หากติดตั้งโปรแกรมบางตัว และ clear ค่าต่าง ๆ หากไม่แน่ใจ

--------------------------------------------------------------------------------
2.15 คำสั่ง runlevel : คู่กับแฟ้ม /etc/inittab เพื่อบอกว่าปัจจุบันอยู่ใน level ใด : ถ้าต้องการเปลี่ยน level ต้องใช้คำสั่ง chkconfig ให้ดูเพิ่มเติมจาก 2.18
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#/sbin/runlevel :: แสดง level ปัจจุบัน
#cat /etc/inittab :: แสดงตาราง กำหนดการสั่งเครื่อง ว่าใช้ level ใด

--------------------------------------------------------------------------------
2.16 คำสั่ง fsck : ซ่อมแซมระบบแฟ้มใน linux
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#fsck / :: ใช้ซ่อม harddisk ในห้อง / เมื่อการ harddisk เกิดปัญหาเกี่ยวกับการปิดเปิด
#fsck /dev/hdc :: ใช้ซ่อม harddisk ที่ชื่อ /dev/hdc ถ้าต่อ harddisk ไว้หลายตัว

--------------------------------------------------------------------------------
2.17 คำสั่ง chown, chgrp : เปลี่ยนเจ้าของ หรือเปลี่ยนกลุ่ม
--------------------------------------------------------------------------------
ตามหัวข้อ 1.2 เรื่องคำสั่ง chmod ทำให้ทราบว่า แฟ้มแต่ละแฟ้มมี 3 ส่วน คือเจ้าของ กลุ่ม และทั่วไป เมื่อต้องการเปลี่ยนความเป็นเจ้าของ หรือกลุ่ม ก็สามารถทำได้ ซึ่งเป็นหลักการง่าย ๆ ไม่ยุ่งยาก
ตัวอย่างคำสั่ง และการใช้งาน
#chown burin:users x :: เปลี่ยนเจ้าของของแฟ้ม x ให้เป็น burin และอยู่ในกลุ่มของ users
#chgrp users y :: เปลี่ยนกลุ่มของแฟ้ม x ให้เป็น users

--------------------------------------------------------------------------------
2.18 คำสั่ง chkconfig : กำหนด หรือแสดง บริการที่สั่งประมวลผลใน level ต่าง ๆ ขณะเปิดเครื่อง
--------------------------------------------------------------------------------
คำว่า level คือระดับในการเปิดเครื่อง ดูได้จากแฟ้ม /etc/inittab โดยโปรแกรมต่าง ๆ ที่สั่งให้ประมวลผล สามารถเลือกให้ทำงานใน level ใดได้ หากสั่งให้ประมวลผลปิด level เมื่อมีการ start linux ใน level หนึ่ง โปรแกรมที่คิดว่าสั่งให้ทำงานขณะเปิดเครื่อง ก็จะไม่ทำงาน
# /etc/inittab
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#id:5:initdefault:
id:3:initdefault:

ตัวอย่างคำสั่ง และการใช้งาน
#/sbin/chkconfig --add mysql :: สั่งให้เพิ่ม mysql เข้าไปในระบบ system services
#/sbin/chkconfig --list :: แสดงรายการโปรแกรมทั้งหมด ที่สั่งให้ทำงานใน level ต่าง ๆ
#/sbin/chkconfig --level 3 sendmail on :: สั่งโปรแกรม sendmail ทำงานใน level 3 (Text mode)
#/sbin/chkconfig --level 5 sendmail on :: สั่งโปรแกรม sendmail ทำงานใน level 5 (X Windows)

--------------------------------------------------------------------------------
2.19 คำสั่ง mount, umount : สั่งเชื่อมต่ออุปกรณ์ หรือ partition เช่น Diskette หรือ Handy drive เป็นต้น
--------------------------------------------------------------------------------
การใช้ mount เป็นสิ่งที่ผู้ดูแลระบบต้องเข้าใจหลักการให้ได้ เพราะเป็นช่องทางในการติดต่อกับอุปกรณ์ต่าง ๆ ล่าสุด ผมต่อ harddisk เข้าไปในเครื่อง server เพิ่มอีก 1 ตัว ซึ่งระบบมอง harddisk ตัวที่เพิ่มเข้าไปเป็น hdc ด้วยคำสั่ง fdisk -l เมื่อต้องการ partition ที่ 1 ของ hdc มาเป็นห้อง /x ก็เพียงแต่ใช้คำสั่งสร้างห้องคือ #mkdir /x สำหรับครั้งแรก แล้วใช้คำสั่ง #mount /dev/hdc1 /x ก็จะใช้ห้อง /x ซึ่งอยู่ใน harddisk อีกตัวหนึ่งได้ทันที
คำสั่งที่เกี่ยวข้องกับคำสั่ง mount
#cat /etc/fstab : ดู file system table เพื่อบอกว่ามีอะไร mount ไว้แล้วบ้าง
#cat /etc/mtab : ดูรายละเอียดการ mount ในอีกรูปแบบหนึ่ง
#cat /proc/mounts : บอกว่ามีอะไร mount ไว้แล้วบ้าง
#cat /proc/partitions : บอกชื่อ และขนาดของแต่ละ partitions
#cat /proc/filesystems : บอกประเภทของ filesystems ที่มีการสนับสนุน
#/sbin/fdisk -l : แสดง partition จาก harddisk ทุกตัวที่เชื่อมต่อในเครื่องนั้น

ตัวอย่างคำสั่ง และการใช้งาน
#mount --bind /var/www /home/yourname/www
#mount แสดงข้อมูลที่เคย mount ไว้ทั้งหมด

วิธีใช้แผ่น Floppy Disk ใน linux
#mkdir /floppy
#mkfs -t ext3 /dev/fd0 1440
#mount -t ext3 /dev/fd0 /floppy
- or -
#mkdir /floppy
#mkfs -t msdos /dev/fd0 1440
#mount -t msdos /dev/fd0 /floppy
ต่อไปในห้อง /floppy ก็คือแผ่น disk ใน drive A ส่วน /dev/fd1 ก็คือ drive B แต่ต้องเริ่มทำใหม่นะครับ
วิธีใช้ Handy Drive เช่น Apacer (ต้อง umount ก่อนดึง apacer ออกก่อนเสมอ)
#mkdir /mnt/apacer (Just first time)
#mount /dev/sda1 /mnt/apacer
...
#cd /
#umount /dev/sda1
- and -
#pico /etc/fstab Add: /dev/sda1 /mnt/apacer auto noauto,user 0 0
วิธีเรียกใช้แฟ้มใน Partition อื่น เช่น WindowsXP
cd / :: ย้ายตัวเองไปยัง root directory
mkdir hd :: สร้างห้องชื่อ hd ซึ่งเป็นห้องเปล่าไม่มีอะไร
fdisk -l :: ดูว่ามี partition อะไรในเครื่องบ้าง ที่ต้องการ mount เข้ากับ /hd
mount /dev/hdb2 /hd :: ทำให้เรียกใช้ /dev/hdb2 จาก /hd ได้ เช่น cd /hd/etc ถ้าใน hdb2 มีห้องชื่อ etc
umount /hd :: ยกเลิกการ mount /hd

วิธีใช้ CDROM
mount :: แสดงรายการอุปกรณ์ หรือห้องต่าง ๆ ที่ถูก mount ไว้แล้ว
mount -t ext3 :: แสดงให้เห็นว่า partition แบบ ext3 มีอะไรถูก mount ไว้บ้าง
mount -t vfat :: แสดงให้เห็นว่า partition แบบ vfat มีอะไรถูก mount ไว้บ้าง
mount /dev/cdrom :: ใช้ติดต่อ CD ROM เมื่อเข้าไปใช้เช่น #cd /mnt/cdrom และใช้ #ls
umount /dev/cdrom :: เพื่อเลิกใช้ CD ROM หรือต้องการดึงแผ่นออก แต่ท่านต้องออกมาก่อนด้วยคำสั่ง #cd / เป็นต้น
eject :: ถ้าไม่ umount ด้านล่าง ก็สั่ง eject เพื่อดีด CD-ROM ออกได้เลยครับ และไม่ต้องสั่ง umount หรือออกจากห้องก่อนนะ

ตัวอย่างผลการใช้คำสั่ง #mount ใน server ตัวหนึ่ง /dev/hda5 on / type ext3 (rw) none on /proc type proc (rw) /dev/hda1 on /boot type ext3 (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) /dev/hda3 on /home type ext3 (rw) none on /dev/shm type tmpfs (rw) /dev/hda2 on /usr type ext3 (rw) /dev/hda6 on /var type ext3 (rw)

--------------------------------------------------------------------------------
2.20 คำสั่ง mkbootdisk : สร้างแผ่น boot disk เพื่อใช้ boot ระบบ linux ขึ้นมาภายหลัง และมีการทำงานแบบ stand alone
--------------------------------------------------------------------------------
คำสั่งนี้ผมเคยใช้ตอนคัดลอก harddisk ที่เป็น linux 2 ตัว แต่ตัวลูกเมื่อนำไปเสียบเข้าเครื่องใหม่ พบว่า boot ด้วยตนเองไม่ได้ จึงต้องหาแผ่น boot จนเข้าไปใน harddisk ได้ จากนั้นก็สั่ง #lilo เพื่อให้การ boot ครั้งต่อไปสามารถทำงานตาม /etc/lilo.conf ได้ตามปกติ ส่วนตัวเลข 2.4.18-14 เป็นเลขรุ่นของ kernel ใน Redhat 8.0 สังเกตเลขนี้ได้ตอน boot เครื่อง
ตัวอย่างคำสั่ง และการใช้งาน
mkbootdisk --device /dev/fd0 2.4.18-14 :: สร้างแผ่น disk เพื่อใช้ boot เข้า linux ในกรณีที่ระบบ boot ของเครื่องมีปัญหา

--------------------------------------------------------------------------------
2.21 คำสั่ง traceroute : แสดงเลข ip ของเครื่องที่ถูกเชื่อมต่อทั้งหมด ไปยังปลายทางที่ต้องการ
--------------------------------------------------------------------------------
ตัวอย่างข้างล่างนี้แสดงให้เห็นว่า เมื่อในวิทยาลัยโยนกเปิดเว็บ www.thai.net จะต้องติดต่อผ่านเครื่องบริการ 8 ตัว ดังตัวอย่างล่างนี้ ถ้าเปิดเว็บไซต์ต่างประเทศ ก็จะมีจำนวนเครื่องในการติดต่อมากขึ้นไปด้วย เครื่องบริการในที่นี้ มักเป็นอุปกรณ์ที่เรียกว่า router และ router ทุกตัวจะมี ip และความสามารถเฉพาะตัวที่ต่างกันไป โดยหน้าที่หลักของ router ก็คือการกำหนดเส้นทางในการติดต่อนั่นเอง
ตัวอย่างคำสั่ง และการใช้งาน
/usr/sbin/traceroute www.thai.net
traceroute to www.thai.net (203.150.13.2), 30 hops max, 38 byte packets
1 door.yonok.ac.th (202.29.78.254) 2.046 ms 1.962 ms 2.532 ms
2 202.28.29.41 (202.28.29.41) 3.703 ms 3.294 ms 3.760 ms
3 UniNet-BKK2-ATM1-0-0.700.uni.net.th (202.28.28.129) 14.185 ms 13.226 ms 14.614 ms
4 202.28.28.18 (202.28.28.18) 13.705 ms 13.227 ms 14.130 ms
5 202.47.255.2 (202.47.255.2) 13.222 ms 13.890 ms 13.210 ms
6 202.129.63.182 (202.129.63.182) 16.649 ms 14.960 ms 15.659 ms
7 juliet-vlan-2.bkk.inet-th.net (203.150.14.22) 14.817 ms 15.573 ms 15.610 ms
8 www.thai.net (203.150.13.2) 15.628 ms 14.775 ms 14.222 ms


--------------------------------------------------------------------------------
2.22 คำสั่ง rpm : ใช้ตรวจสอบ เพิ่ม หรือลบ package ของระบบ linux เกือบทั้งหมด
--------------------------------------------------------------------------------
ในกรณีที่ท่านมีโปรแกรมตัวใหม่มา สามารถที่จะลบโปรแกรมเพิ่มโดยใช้คำสั่ง rpm ได้ หรือต้องการตรวจสอบว่า มี package บางตัว install อยู่หรือไม่ หรือจะยกเลิกโปรแกรมบางตัวออกจากระบบก็ทำได้ หรือจะแสดงรายชื่อ package ทั้งหมดในระบบก็ทำได้อีก รวมทั้งการตรวจ version ของ package แต่ละตัว จากประสบการณ์ ไม่แน่ใจว่าเกิดจากอะไร เมื่อลง Redhat 7.2 แล้ว แต่ระบบไม่บริการ pop3 จึงได้ทำการ mount /dev/cdrom จากนั้นก็ทำการ install package pop เพิ่มเข้าไป ที่รู้เพราะลองใช้คำสั่ง telnet localhost 110 แล้ว error จึงต้องทำการเพิ่ม package pop เข้าไปใหม่ โดยใช้คำสั่ง rpm -i imap-4.7-5.i386.rpm ที่รู้เพราะได้ใช้ cd เข้าไปในห้อง /mnt/cdrom/RedHat/RPMS จึงพบแฟ้มมากมายที่สามารถ install เพิ่มได้
ตัวอย่างคำสั่ง และการใช้งาน
rpm -i imap-4.7-5.i386.rpm :: ใช้ install package pop เข้าไปใน linux ใหม่ เพราะไม่มี และให้ดูเพิ่มเติมจาก 8.99 เกี่ยวกับการติดตั้งโปรแกรมจาก CD-ROM
rpm -qa|grep imap :: ใช้ดูว่ามี package อะไรบ้างที่ขึ้นต้นด้วย imap
rpm -qa :: ใช้ดูรายชื่อ package ทุกตัวที่ install ไว้แล้ว
rpm -q telnet :: ใช้ตรวจว่ามี package ชื่อ telnet อยู่หรือไม่
rpm -qpl imap-4.7-5.i386.rpm :: แสดงชื่อแฟ้มใน package แต่ต้องเข้าไปที่ /mnt/cdrom/RedHat/RPMS ก่อนนะครับ
rpm -qf /usr/sbin/vi :: จะแสดง vim-minimal-5.6-11 ซึ่งเป็นรุ่นของ vi นั้น
rpm -qf /usr/sbin/httpd :: จะได้ apache-1.3.12-2 ซึ่งเป็นรุ่นที่ติดตั้งมาใน linux 6.2
rpm -e apache-1.3.12-2 :: ลบ หรือ erase โปรแกรม apache-1.3.12-2 ออกจากเครื่อง
rpm -Fvh openssl-0.9.5a-2.6.x.i386.rpm :: Upgrade โปรแกรม แต่ต้องลงโปรแกรมก่อนมิเช่นนั้น ไม่สำเร็จนะครับ
rpm -qi vsftpd :: แสดงรายละเอียดของ Application เช่น ขนาด วันติดตั้ง รุ่น ผู้ผลิต เป็นต้น

--------------------------------------------------------------------------------
2.23 คำสั่ง SU : ขอเปลี่ยนตนเองเป็น Super user หรือ root เพื่อใช้สิทธิ์สูงสุดในการบริหารระบบ ที่ผู้ใช้ปกติทำไม่ได้
--------------------------------------------------------------------------------
การจะใช้ su ได้จะต้องเป็นผู้ใช้ตามปกติ เมื่อพิมพ์ su แล้วระบบจะถามรหัสผ่านของ user root หากพิมพ์รหัสผ่านถูกต้อง ท่านก็จะสามารถกระทำการใด ๆ ก็ได้ ในฐานะ root เพราะ root หรือ super user คือผู้ที่มีอำนาจสูงสุดในระบบ เช่น เพิ่มผู้ใช้ท่านใหม่ ลบผู้ใช้คนเดิม เป็นต้น (เพียงแต่พิมพ์คำว่า su ท่านก็สามารถเปลี่ยนสิทธิ์ได้แล้ว ถ้าท่านมีรหัสผ่านของ su) เดิมผมใช้แค่คำว่า su ต่อมาคุณประเสริฐ แนะนำว่าต้องใช้ su - จึงจะสมบูรณ์ พอทดสอบก็พบว่า $PATH ที่ได้แตกต่างกันจริง
ตัวอย่างคำสั่ง และการใช้งาน
#su - :: เปลี่ยนตนเองเป็น super user เพื่อกระทำการใด ๆ ก็ได้กับตัวระบบ
#su prasert :: ไม่ว่าขณะที่ login เป็น user ใด เมื่อต้องการเปลี่ยนเป็น user prasert ก็ไม่ต้อง logout แล้ว login ใหม่ ใช้คำสั่งนี้ได้เลย

--------------------------------------------------------------------------------
2.24 คำสั่ง useradd : เพิ่มผู้ใช้รายใหม่เข้าไปในระบบ
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#useradd theman :: เพิ่มผู้ใช้รายใหม่เข้าไปในระบบชื่อ theman ในกลุ่ม theman และมี home directory เป็น /home/theman
#useradd -g users -d /home/theman -c "user name here" theman :: เพิ่มผู้ใช้รายใหม่เข้าไปในระบบชื่อ theman

--------------------------------------------------------------------------------
2.25 คำสั่ง userdel : ลบผู้ใช้รายเดิม ออกจากระบบ
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#userdel -r theman :: ลบ theman และ home directory ของ theman ออกหมด

--------------------------------------------------------------------------------
2.26 คำสั่ง usermod : แก้ไขข้อมูลของผู้ใช้ได้
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#usermod -s /rbin/menu theman :: กำหนดให้ shell สำหรับ user ที่ชื่อ theman ใหม่ เพื่อจำกัดสิทธิ์ในการเข้าใช้ shell
#usermod -d /home/theman theman :: กำหนดให้ theman มี homedirectory อยู่ที่ /home/theman
#usermod -c "Mr.Suwit Somsupabrungyod" theman :: กำหนดให้ comment หรือชื่อ เป็น Mr.Suwit Somsupabrungyod ซึ่ง comment จะไปแสดงผลให้เห็นชัดเจนตอนที่ใช้ pine เมื่อพิมพ์คำว่า theman ในช่อง to ขณะที่กำลัง compose จะแสดง comment หน้า email ให้ทันที

--------------------------------------------------------------------------------
2.27 คำสั่ง crontab : ตั้งเวลาสั่งงานคอมพิวเตอร์
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#crontab -l :: แสดงกำหนดการของการสั่งให้คอมพิวเตอร์ทำงานอย่างอัตโนมัติ ตามเวลาที่กำหนด
#cat /etc/crontab :: แสดงตาราง crontab ในเครื่อง

--------------------------------------------------------------------------------
2.28 คำสั่ง lspci : ตรวจสอบอุปกรณ์ที่เชื่อมต่อภายในเครื่อง
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#lspci
00:00.0 Host bridge: Intel Corp . 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 03)
00:01.0 PCI bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03)
00:07.0 ISA bridge: Intel Corp. 82371AB/EB/MB PIIX4 ISA (rev 02)
00:07.1 IDE interface: Intel Corp. 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.2 USB Controller : Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01)
00:07.3 Bridge: Intel Corp. 82371AB/EB/MB PIIX4 ACPI (rev 02)
00:0f.0 PCI bridge: Digital Equipment Corporation DECchip 21152 (rev 03)
00:11.0 Ethernet controller: 3Com Corporation 3c905B 100BaseTX [Cyclone] (rev 24)
01:00.0 VGA compatible controller: ATI Technologies Inc 3D Rage Pro AGP 1X/2X (rev 5c)


--------------------------------------------------------------------------------
2.29 คำสั่ง nmap : ตรวจสอบเครือข่ายแบบกวาดทั้งในเครื่อง และ class C
--------------------------------------------------------------------------------

ตัวอย่างคำสั่ง และการใช้งาน
#nmap -sP 202.29.78.*
Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Host (202.29.78.0) seems to be a subnet broadcast address (returned 1 extra pings).
Note -- the actual IP also responded.
Host www.isinthai.com (202.29.78.1) appears to be up.
Host course.yonok.ac.th (202.29.78.5) appears to be up.
Host yonok.ac.th (202.29.78.12) appears to be up.
Host w2kdhcp.yonok.ac.th (202.29.78.17) appears to be up.
Host (202.29.78.31) appears to be up.
Host (202.29.78.32) appears to be up.
Host (202.29.78.33) appears to be up.

#nmap -sT www.yonok.ac.th (on TCP)
Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Interesting ports on yonok.ac.th (202.29.78.12):
(The 1590 ports scanned but not shown below are in state: closed)
Port State Service
21/tcp open ftp
22/tcp open ssh
25/tcp open smtp
53/tcp open domain
80/tcp open http
109/tcp open pop-2
110/tcp open pop-3

#nmap www.yonok.ac.th -sU (on UDP)
Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Interesting ports on yn1.yonok.ac.th (202.29.78.12):
(The 1465 ports scanned but not shown below are in state: closed)
Port State Service
53/udp open domain
111/udp open sunrpc
867/udp open unknow

คำสั่งยูนิกส์ Command Line (Linux ตอนที่1)

ls
เป็นคำสั่งที่ใช้สำหรับแสดงแฟ้มข้อมูล (เช่นเดียวกับ dirของDOS) มากจากคำว่า list
รูปแบบคำสั่ง ls [option] [file]
option ที่มักใช้กันใน ls คือ
-l จะแสดงผลลัพธ์แบบ Long Format ซึ่งจะแสดง Permission ของแฟ้มด้วย
-a จะแสดงแฟ้มข้อมูลทั้งหมด
-F จะแสดง / หลัง Directory และ * หลังแฟ้มข้อมูลที่ execute ได้
ตัวอย่างการใช้งาน ls –l ls -al ls -F

adduser
คำสั่งเพิ่ม User ให้กับระบบ Unix,Linux
รูบแบบการใช้งาน adduser -g (group) -d (Directory) (User)
ตัวอย่าง adduser -g root -d /home/user1 user สร้าง User ชื่อ Login คือ user1 เป็นสมาชิกในกลุ่ม root

useradd
คำสั่งเพิ่ม User ให้กับระบบ Unix,Linux (ใช้เหมือนกับคำสั่ง adduser)
รูบแบบการใช้งาน useradd -g (group) -d (Directory) (User)
ตัวอย่าง useradd -g root -d /home/user1 user สร้าง User ชื่อ Login คือ user1 เป็นสมาชิกในกลุ่ม root

userdel
คำสั่งลบ User ออกจากระบบ Unix,Linux
รูบแบบการใช้งาน userdel [option] (Username)
ตัวอย่าง userdel -r root user1 ลบ User ชื่อ Login คือ User1 และ -r คือให้ลบ Home Directoryของ User1 ด้วย
passwd
คำสั่งกำหนดและแก้ไขรหัสผ่านของ User ของระบบ Unix,Linux
รูบแบบการใช้งาน passwd [Username]
ตัวอย่าง passwd user1 (กำหนดรหัสผ่านให้ User1 ถ้าไม่พิมพ์ ชื่อ User ระบบUnixจะหมายความว่าแก้ไขรหัสผ่าน
ของคนที่Loginเข้ามา)

alias
คำสั่งกำหนดคำสั่งย่อของระบบ Unix,Linux (คล้ายกับคำสั่ง SETในDOSแต่สามารถใช้เปฝ้นคำสั่ง RUNได้)
รูบแบบการใช้งาน alias [ชื่อใหม่=ข้อความ]
ตัวอย่าง alias copy=cp กำหนดให้พิมพ์ copy แทนคำสั่ง cpได้

bash
คำสั่งเรียกใช้ Bourne again shellของระบบ Unix,Linux
รูบแบบการใช้งาน bash
ตัวอย่าง bash [Enter] ( เรียกใช้ Bourne again shell)

bc
คำสั่งเรียกใช้โปรแกรมคำนวณเลขของระบบ Unix,Linux
รูบแบบการใช้งาน bc [-lwsqv] [option] [file]
ตัวอย่าง bc [Enter] 1+2 [Enter] 1^2 [Enter] a=3 [Enter] b=4 [Enter] a*b [Enter] x=2;y=5;x+y[Enter] [Ctrl-d] เพื่อออก
หมายเหตุ:คำสั่งนี้จะใช้ได้ต้องInstall Packet ลงไปก่อน

cp
เป็นคำสั่งที่ใช้สำหรับสำเนาแฟ้มข้อมูล (เช่นเดียวกับcopyของDOS) มาจากคำว่า copy
รูปแบบคำสั่ง cp source target
ตัวอย่างการใช้งาน #cp test.txt /home/user1

cal
คำสั่งแสดงปฏิทินของระบบ Unix,Linux
รูบแบบการใช้งาน cal
ตัวอย่าง cal [Enter](สั่งให้ระบบแสดง ปฏิทินเดือน ปัจจุบัน)
cal -y [Enter](สั่งให้ระบบแสดง ปฏิทินปี ปัจจุบัน)

cat
คำสั่งแสดงข้อความในFileของระบบ Unix,Linux (คล้ายกับคำสั่งTypeของDOS)
รูบแบบการใช้งาน cat
ตัวอย่าง cat /home/user1 | more อ่านข้อมูลจากไฟล์/home/user1ถ้ายาวเกินหน้าให้หยุดทีละหน้าจอ

C Compiler
คำสั่งCompile ภาษาCของระบบ Unix,Linux (คล้ายกับคำสั่งTypeของDOS)
รูบแบบการใช้งาน cc [filename]
ตัวอย่าง cc /home/user1/industry.c จะสั่งให้ระบบCompile ภาษาC ไฟล์ชื่อ industry.c ที่ Directory /home/user1

cd
คำสั่งChange Directoryของระบบ Unix,Linux (คล้ายกับคำสั่งCDของDOS)
รูบแบบการใช้งาน cd [directory]
ตัวอย่าง cd /etc [Enter]ไปDirectory etc
cd ..[Enter] ย้ายไปDirectoryอีก1ชั้น

chfin
คำสั่งChange your finger informationของระบบ Unix,Linux (เป็นการกำหนดข้อมูลของUser
เช่น ชื่อเต็ม ที่อยู่ เบอร์โทรศัพท์)
รูบแบบการใช้งาน chfn [username]
ตัวอย่าง chfn User1 กำหนดรายละเอียดUser1

chgrp
คำสั่งChange Groupของระบบ Unix,Linux (เป็นการเปลี่ยนกลุ่มเจ้าของไฟล์)
รูบแบบการใช้งาน chgrp [-chfRv] (Group) (File)
ตัวอย่าง chgrp root /root/* เปลี่ยนGroupให้กับไฟล์ทุกไฟล์ในไดเรคทอรี่ /root ให้เป็น Group root

chmod
คำสั่งChange Modeของระบบ Unix,Linux (เป็นการเปลี่ยนสิทธิการเข้าถึงไฟล์)
รูบแบบการใช้งาน chmod [สิทธิ] (File)
ตัวอย่าง กำหนดสิทธิให้กับไฟล์ชื่อtest คือ chmod 754 test หรือ chmod go +r-w testให้กับไฟล์ทุกไฟล์ chmod o-r *
ตัวเลขMode rwx = 7 ; rw - =6 ; r-x =5 ; r- - = 4 ; - wx = 3 ; - w - = 2 ; - - x = 1 ; - - = 0
การกำหนดสิทธิกำหนดได้2ลักษณะคือ
1.กำหนดโดยใช้อักษรย่อกลุ่ม
2.ใช้รหัสเลขฐาน2แทนสิทธิ (1 คืออนุญาต)
กลุ่มผู้ใช้ User Group Other = ugo เช่น go-r-w+x คือกลุ่ม และคนอื่นไม่มีสิทธิอ่านเขียนแต่Runได้
สิทธิ์การใช้ -rwx rwx rwx = Read Write Execute
รหัสเลขฐาน 111 101 100 = 754 คือเจ้าของไฟล์ใช้ได้ครบ คน Group เดียวกันอ่านExecuteได้นอกนั้นอ่านได้อย่างเดียว

chown
คำสั่งChange Ownerของระบบ Unix,Linux (เป็นการเปลี่ยนเจ้าของไฟล์)
รูบแบบการใช้งาน chown [ซื่อเจ้าของไฟล์] (ชื่อFile)
ตัวอย่าง chown user1 filename คือเปลี่ยนเจ้าของไฟล์ชื่อ filename เป็นUser1
chown -R user1.root dirname คือเปลี่ยนทั้งเจ้าของไฟล์และกลุ่มไปพร้อมกันทุกไฟล์ใน Sub dirname.

chsh
คำสั่งchshของระบบ Unix,Linux (เป็นการเปลี่ยนShell ให้ User)
รูบแบบการใช้งาน chsh [Username]
ตัวอย่าง chsh user1 [Enter] /bin/bash [Enter]

clear
คำสั่งclearของระบบ Unix,Linux (เป็นการลบข้อความบนจอภาพ คล้ายกับคำสั่ง clsใน dos)
รูบแบบการใช้งาน clear
ตัวอย่าง clear [Enter]

cal
คำสั่งแสดงปฏิทินของระบบ Unix,Linux
รูบแบบการใช้งาน cal
ตัวอย่าง cal [Enter](สั่งให้ระบบแสดง ปฏิทินเดือน ปัจจุบัน)
cal -y [Enter](สั่งให้ระบบแสดง ปฏิทินปี ปัจจุบัน)

mesg
mesg ดู status การรับการติดต่อของ terminal
mesg y เปิดให้ terminal สามารถรับการติดต่อได้
mesg n ปิดไม่ให้ terminal สามารถรับการติดต่อได้

date
ใช้แสดง วันที่ และ เวลา
ตัวอย่าง date 17 May 2004

df
คำสั่งdf ของระบบ Unix,Linux (เป็นการตรวจสอบการใช้พื่นที่บนฮาร์ดดิสก์)
รูบแบบการใช้งานdf [option] [file]
ตัวอย่าง df [Enter]

dmesg
คำสั่งdmesgของระบบ Unix,Linux (เป็นการให้แสดงผลเหมือนตอน Boot)
รูบแบบการใช้งาน dmesg
ตัวอย่าง dmesg | more [Enter]
หมายเหตุ คำสั่งนี้ ใช้ตรวจสอบ เมื่อเกิดปัญหา เช่น Linux ไม่รู้จัก Driver CD-Rom หรือปัญหาอื่นๆ

echo
คำสั่งechoของระบบ Unix,Linux (เป็นการให้แสดงข้อความ เหมือนกับ ECHOของDOS)
รูบแบบการใช้งาน echo (ข้อความที่ต้องการให้แสดงผล)
ตัวอย่าง echo my name is user1
echo Hello > /dev/tty2 ส่งข้อความ Hello ไปออกจอเทอร์มินอลที่2

ed
คำสั่ง ed ของระบบ Unix,Linux (โปรแกรมแก้ไขข้อความใน Text file เหมือนกับคำสั่ง edlinของDOS)
รูบแบบการใช้งาน ed (fileName)
ตัวอย่าง ed /home/user/test (ออกกดq)
สำหรับคนที่ไม่ถนัดคำสั่งนี้แนะนำให้ใช้คำสั่ง picoหรือvi หรือemacsแทนได้เช่นกัน

emacs
คำสั่ง emacs ของระบบ Unix,Linux (โปรแกรมแก้ไขข้อความใน Text file )
รูบแบบการใช้งาน emacs (fileName)
ตัวอย่าง emacs /home/user/test (help กด Ctrl - h ; ออกกด Ctrl - x Ctrl - c)

exit
คำสั่ง exit ของระบบ Unix,Linux (ออกจากระบบยูนิกส์ )
รูบแบบการใช้งาน exit
ตัวอย่าง exit

finger
คำสั่ง finger ของระบบ Unix,Linux (แสดงชื่อUserที่กำลังLoginเข้ามาแต่คำสั่ง Whoจะให้รายละเอียดดีกว่า)
รูบแบบการใช้งาน finger [username]
ตัวอย่าง finger user1 แสดงชื่อและรายละเอียด user1

fsck
คำสั่ง fsck ของระบบ Unix,Linux (เป็นคำสั่ง ตรวจสอบและซ่อมแซม Linux file system เหมือนกับ
คำสั่งScandisk ของDos)
รูบแบบการใช้งาน fsck [option]
ตัวอย่าง /sbin/fsck -a /dev/hd1

ftp
คำสั่ง ftp ของระบบ Unix,Linux (เป็นโปรแกรมรับ-ส่งไฟล์ )
รูบแบบการใช้งาน ftp (IP or Name of FTP Server )
ตัวอย่าง ftp 132.209.1.2 [Enter]

Login:anonymous , Password: Username@YourDomain.com
คำสั่งที่เกี่ยวข้อง ls - ดูไฟล์ ; pwd -ดูdir. ที่อยู่ ;cd - เปลี่ยน dir ;lcd - เปลี่ยน local dir ;mput* -ส่งไฟล์ ;mget – รับ
ไฟล์ ;bye - ออก

grep
คำสั่ง grep ของระบบ Unix,Linux (เป็นการสั่งให้ค้นหาตามเงื่อนไข )
รูบแบบการใช้งาน grep (option)
ตัวอย่าง grep -i ftp /etc/test ค้นหาบรรทัดที่มีคำว่า "ftp"ไม่สนใจพิมพ์เล็ก-ใหญ่ จาดไฟล์ /etc/test

groupadd
คำสั่ง groupadd ของระบบ Unix,Linux (เป็นการเพิ่มรายชื่อกลุ่มของ User)
รูบแบบการใช้งาน groupadd (GroupName )
ตัวอย่าง #groupadd staff สร้างกลุ่มของ User ชื่อ Staff เพิ่มให้ระบบ

groupdel
คำสั่ง groupdel ของระบบ Unix,Linux (เป็นการลบรายชื่อกลุ่มของ User)
รูบแบบการใช้งาน groupadd (GroupName )
ตัวอย่าง #groupdel staff ลบกลุ่มของ User ชื่อ Staffออกจากระบบ

gzip/gunzip
คำสั่งgzip/gunzipของระบบ Unix,Linux (เป็นการบีบอัดไฟล์หรือขยายบีบอัดไฟล์)
รูบแบบการใช้งาน gzipหรือgunzip (-cdfhlLnNrtv19 ) [file]
ตัวอย่าง #gzip -9vr /home/samba/* บีบอัดไฟล์ข้อมูลทุกไฟล์ ในSub /home/samba จะเปลี่ยนเป็นนามสุกล .gz
#gunzip -dvr /home/samba/* คลายการบีบอัดไฟล์ข้อมูลทุกไฟล์ที่สกุล .gz ในSub /home/samba

halt
คำสั่ง halt ของระบบ Unix,Linux (เป็นการสั่งให้เครื่องหยุดทำงาน)
รูบแบบการใช้งาน halt [-n] [-w] [-d] [-f] [-I] [-p]
ตัวอย่าง #halt
คำสั่งที่เกี่ยวข้อง คือ Shutdown ; init0 , reboot

history
คำสั่ง history ของระบบ Unix,Linux (เป็นการดูประวัติการใช้คำสั่งในCommand line คล้ายกับ
การกดF7ในDOSคือเรียกใช้คำสั่งDos key)
รูบแบบการใช้งานhistory [n] [-r wan [filename] ]
ตัวอย่าง #history 20 ดูคำสั่งที่เพิ่งใช้ไป20คำสั่งที่แล้ว

ifconfig
คำสั่ง history ของระบบ Unix,Linux (เป็นการตรวจสอบกำหนดค่าNetworkของLan Card)
รูบแบบการใช้งาน ifconfig [option]
ตัวอย่าง #ifconfig

ipchains
คำสั่ง ipchains ของระบบ Unix,Linux (เป็นคำสั่งสำหรับกำหนดควบคุม การรับส่งผ่านข้อมูลของ Firewall)
รูบแบบการใช้งาน ipchains [parameter] command [option]
ตัวอย่าง #ipchains -L ดูสถานะการ Set IPchainsในปัจจุบัน

jobs
คำสั่ง jobs ของระบบ Unix,Linux (เป็นคำสั่งสำหรับกำหนดควบคุม การรับส่งผ่านข้อมูลของ Firewall)
รูบแบบการใช้งาน jobs
ตัวอย่าง #sleep 20 & jobs

kill
คำสั่ง kill ของระบบ Unix,Linux (เป็นคำสั่งสำหรับยกเลิก Process)
รูบแบบการใช้งาน kill [option] (process ID)
ตัวอย่าง ps -A ดูหมายเลขที่ช่อง PIDของProcess ที่ต้องการลบ
Kill -9

login
คำสั่ง login ของระบบ nnn แทนnnnด้วยหมายเลขPID -9 คือบังคับฆ่าให้ตาย
Unix,Linux (เป็นคำสั่งการเข้าระบบหรือเปลี่ยน User Login) รูบแบบการใช้งาน login [fp] (UserName)
ตัวอย่าง #login:root

mkdir
เป็นคำสั่งที่ใช้สำหรับการสร้าง directory (ในทำนองเดียวกับ dos) มาจากคำว่า make directory
รูปแบบของคำสั่งmkdir mkdir [option] [file]
โดย option ที่มักใช้กันใน mkdir คือ
-m จะทำการกำหนด Permissioin (ให้ดูคำสั่ง chmod เพิ่มเติม)
-p จะทำการสร้าง Parent Directory ให้ด้วยกรณีที่ยังไม่มีการระบุ directory ในที่นี้อาจเป็น relative
หรือ absolute path ก็ได้
ตัวอย่าง
mkdir /home
mkdir -p -m755 ~/้home/user1

mv
เป็นคำสั่งที่ใช้สำหรับการย้ายแฟ้มข้อมูลและ Directory รวมถึงการเปลี่ยนชื่อด้วย (ในทำนองเดียวกับ dos)
มาจากคำว่า move
รูปแบบคำสั่ง mv source target
ตัวอย่าง mv *.tar /backup
mv test.txt old.txt
mv bin oldbin

more
คล้ายกับคำสั่ง cat ไม่เหมาะกับการดูข้อมูลที่มีความยาวมากๆ ดังนั้น จึงได้มีการพัฒนา more ขึ้น
เพื่อช่วยให้สามารถดูข้อมูลที่มีขนาดยาวได้เป็นช่วงๆ
รูปแบบคำสั่ง more file
ภายในโปรแกรม more จะมีคำสั่งเพื่อใช้งานคราวๆ ดังนี้
= แสดงเลขบรรทัด
q ออกจากโปรแกรม
เลื่อนไปยังหน้าถัดไป เลื่อนไปยังบรรทัดถัดไป
h แสดง help
ตัวอย่าง more test.txt

man
คำสั่ง man ของระบบ Unix,Linux (เป็นคำสั่งแสดงข้อความ อธิบายการใช้คำสั่ง)
รูบแบบการใช้งานman (Command)
ตัวอย่าง #man ls
หมายเหตุ เมื่อต้องการออก กด q ;ใช้[Spacebar] เลื่อนหน้าถัดไป ; ใช้ลูกศรขึ้นดูหน้าผ่านมา

mount
คำสั่ง mount ของระบบ Unix,Linux (เป็นคำสั่งเชื่อมต่ออุปกรณ์เข้ากับระบบ)
รูบแบบการใช้งาน mount (-t type) DeviceDriver MountPoint
ตัวอย่าง # การ Mountแบบที่1 CdRom mount -t iso9660 /dev/cdrom /mnt/cdrom
#การ Mount CdRom แบบที่2 mount /dev/cdrom (เมื่อmountแล้วCDจะอยู่ที่ /mnt/CdRom ยกเลิกดูคำสั่ง Unmount)

rmdir
เป็นคำสั่งที่ใช้สำหรับการลบ directory (ในทำนองเดียวกับ dos) มาจากคำว่า remove directory
โครงสร้างคำสั่ง
rmdir [option] [file]
โดย option ที่มักใช้กันใน mkdir คือ -p จะทำการลบ Child และ Parent Directory ตามลำดับ
directory ในที่นี้อาจเป็น relative หรือ absolute path ก็ได้ ตัวอย่าง rmdir /home

tar
เป็นคำสั่งเพื่อการ backup และ restore file ทั้งนี้การ tar จะเก็บทั้งโครง สร้าง directory และ file permission ด้วย
(เหมาะสำหรับการเคลื่อนย้าย หรือแจกจ่ายโปรแกรมบนระบบ UNIX) มาจากคำว่า tape archive
รูปแบบคำสั่ง tar [option]... [file]...
โดย option ที่มักใช้กันใน echo คือ
-c ทำการสร้างใหม่ (backup)
-t แสดงรายชื่อแฟ้มข้อมูลในแฟ้มที่ backup ไว้
-v ตรวจสอบความถูกต้องของการประมวลผล
-f ผลลัพธ์ของมาที่ file
-x ทำการ restore
ตัวอย่าง tar -xvf data.tar

talk
คำสั่งที่ใช้สำหรับการพูดคุยระหว่างผู้ใช้ด้วยกันบนระบบ ซึ่งผู้ใช้ทั้งทั้ง 2 ฝ่ายจะต้องพิมพ์คำสั่ง Talk ถึงกันก่อน จึงจะเริ่มการสนทนาได้
รูปแบบคำสั่ง talk user[@host] [tty]
กรณีไม่ระบุ host โปรแกรมจะถือว่าหมายถึงเครื่องปัจจุบัน (นอกจากนี้ยังมีคำสั่ง ytalk ซึ่งสามารถพูดคุยได้พร้อม
กันมากกว่า 2 คน) ซึงบางกรณีเราอาจจะต้องระบุ tty ด้วยหากมีผู้ใช้ Log in เข้าสู่ระบบด้วยชื่อเดียวกันมากกว่า 1 หน้าจอ
ตัวอย่าง talk m2k@nanastreet.com

write
คำสั่งใช้เพื่อการส่งข้อมูลทางเดียวจากผู้เขียนไปถึงผู้รับบนเครื่องเดียวกันเท่านั้น
รูปแบบคำสั่ง write user [tty]
เมื่อมีการพิมพ์คำสั่ง write ผู้ใช้จะเห็นข้อความซึ่งจะแสดงว่าข้อความดังกล่าวถูกส่งมาโดยใคร ซึ่งหากผู้รับต้องการ
ตอบกลับ ก็จะต้องใช้คำสั่ง write เช่นกัน เมื่อพิมพ์เสร็จแล้วให้พิมพ์ตัวอักษร EOF หรือ กด CTRL+C เพื่อเป็น
การ interrupt ทั้งนี้ข้อความที่พิมพ์หลังจาก write จะถูกส่งหลังจากการกด Enter เท่านั้น
ตัวอย่าง write m2k

who am i
คำสั่งใช้เพื่อแสดงว่าผู้ใช้ซึ่ง login เข้าสู่ระบบนั้น (ตัวเราเอง) login ด้วยชื่ออะไร
รูปแบบคำสั่ง/ตัวอย่าง whoami หรือ who am i (บน SUN OS หรือ UNIX บางตัวเท่านั้น)

file
คำสั่งfileบนระบบ DOS/Windows นั้น ประเภทของแฟ้มข้อมูลจะถูกระบุด้วยนามสกุล แต่ใน UNIX จะไม่มี
นามสกุลเพื่อใช้ระบุประเภทของแฟ้มข้อมูล ดังนั้นการหาประเภทของแฟ้มข้อมูลจะดูจาก Context ภายใน
ของแฟ้ม ซึ่งคำสั่ง file จะทำการอ่าน Content และบอกประเภทของแฟ้มข้อมูลนั้นๆ
รูปแบบคำสั่ง file [option]... file
ตัวอย่าง file /bin/sh file report1.doc

free
แสดงหน่วยความจำที่เหลืออยู่บนระบบ
โครงสร้างคำสั่ง free [-b|-k|-m]
โดย option ที่มักใช้กันใน free คือ
-b แสดงผลลัพธ์เป็นหน่วย byte
-k แสดงผลลัพธ์เป็นหน่วย kilobyte
-m แสดงผลลัพธ์เป็นหน่วย megabyte
ตัวอย่าง free free –b free -k

pwd
เป็นคำสั่งที่ใช้สำหรับแสดง Directory ปัจจุบัน (ในทำนองเดียวกับการพิมพ์ cd บน DOS) มาจากคำว่า print work directory
รูปแบบคำสั่ง / ตัวอย่าง pwd

uname
คำสั่งแสดง ชื่อและรุ่นของ OS ชื่อและรุ่นของ cpu ชื่อเครื่อง
ตัวอย่าง uname -a

hostname
คำสั่งแสดงชื่อเครื่องที่ใช้อยู่
ตัวอย่าง hostname

tty
แสดงหมายเลข terminal ที่ใช้งานอยู่
ตัวอย่าง tty

id
ใช้แสดงชื่อและกลุ่มมของผู้ใช้งาน
ต้วอย่าง id

วันพฤหัสบดีที่ 7 เมษายน พ.ศ. 2554

Installing LAMP (Linux, Apache, MySQL, PHP)

Firstly open a terminal by clicking Applications -> Accessories -> Terminal. Do not be frightened of the terminal though, it is one of GNU+Linux's most powerful tools; in this case it makes working through the article easy, all the reader has to do is copy and paste from article to the terminal. Firstly select then click Edit -> Copy on the line below:
sudo apt-get install apache2 php5 php5-gd mysql-server php5-mysql apache2-dev php5-dev php-pear make vim-full python2.5

Then click Edit -> Paste in the terminal. Note: when the tutorial says Copy or Paste, Ctrl-c (for copy) and Ctrl-v (for paste) can be used as well. Just as in other operating systems, middle-click also works for copy/paste operations.

Press Enter and fill-in the administrator password. This will install the software required for later steps. Next open the /etc/php5/apache2/php.ini file by selecting, then clicking Edit -> Copy on the text below:
gksu gedit /etc/php5/apache2/php.ini &

Edit -> Paste this into the terminal and press Enter, opening a text editor. Do not do anything with this yet, return to the terminal, it will be required later.
Download and Install Xdebug

Select then Edit -> Copy the following:
sudo pecl install xdebug-beta

Then click Edit -> Paste to download and install Xdebug (the PHP debugger). This last command will spew lots of data into the terminal, in the last few lines is a note showing where Xdebug has been installed. It will look similar to:
Installing
'/var/tmp/pear-build-root/install-xdebug-2.0.0RC4//usr/lib/php5/20060613+lfs/xdebug.so'

Or:
Installing '/usr/lib/php5/20060613+lfs/xdebug.so'

Select the /usr/lib/php5/20060613+lfs/xdebug.so part in the terminal with the cursor, then click Edit -> Copy. This line may vary for different versions of XDebug, particularly the part which is a date, if in doubt select from /usr/lib/ up to (and including) xdebug.so.

Bring back the text editor opened earlier, search through the file (pressing Ctrl-f then entering ‘module settings’ works) and find the section marked:
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

Click the empty line beneath it (or create one) and enter:
zend_extension=

Then click Edit -> Paste to paste the location of Xdebug into the file. The zend_extension line should look similar to:
zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so

Having done this press Enter afterwards to create a new line (there are more settings to be pasted into the file).

Select the text below, and Edit -> Copy:
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=

; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32

Return to the php.ini file in the text editor. Edit -> Paste beneath the zend_extension line, this should put the lines copied above into the php.ini file. Next click File -> Save, and close the text editor. Select then Edit -> Copy the following and Edit -> Paste into the terminal to restart Apache:
sudo /etc/init.d/apache2 restart
Configure Vim for PHP Debugging

Now a plugin for Vim which enables PHP debugging is required . Firstly Vim needs a directory for plugins: from the main menu click Places -> Home Folder, this should open a new file browser window. From this window, click View -> Show Hidden Files and check whether a directory named .vim exists (note the full stop at the start of the directory name), if not right-click, select Create Folder (and enter ‘.vim’) to create it.

Open a Web browser and go to this address:
http://www.vim.org/scripts/script.php?script_id=1929

Download this script—currently named debugger.zip—to the .vim directory (hidden files can be shown in the save as box by right-clicking in the file list and selecting Show Hidden Files). From the file browser opened earlier double-click the zip file, then in the window that appears right-click the plugin directory and click Extract. Click Extract to extract the plugin to the .vim directory (check the extract file selection box has defaulted to the .vim directory before extracting, if the files are not in that directory the plugin will not work). The PHP debugging script for Vim should now be installed.

To check the plugin is where it should be, navigate to the: .vim/plugin/ directory using the file browser. Inside this directory should be two files:

* debugger.py
* debugger.vim

PHP Debugger Testing

To test the debugger start Vim by pressing Alt-F2 on the keyboard, type gvim in the box provided, then press Enter. Note: there is a main menu entry for Vim, but it is hidden by default. Right-click on the main menu (top-left of the screen) and click Edit Menus to rectify this. Also required is a PHP script (on the local machine). Open the script in a Web browser but add ?XDEBUG_SESSION_START=1 on the end of the URL (as usual Edit -> Copy/Paste can be used to copy/paste from this article). For example, the URL might look similar to:
http://localhost/test.php?XDEBUG_SESSION_START=1

Press F5 in Vim, then quickly switch to the Web browser and press the Reload button. This must be done within five seconds or Vim will display an error. Don't worry if it does though, just press F5 again. When successfully debugging Vim should stop on the first line of PHP code in the file, it also shows help on how to step-over, step-into, and run etc. use that to learn the commands.

The screenshot below shows Vim debugging PHP. Note: if Vim does nothing when F5 is pressed, it has not been setup correctly, check that the plugin has been installed correctly

Installing Xdebug on Ubuntu 10.04

Install Xdebug

sudo apt-get install php5-xdebug

Update xdebug.ini
Now we need to update the xdebug.ini file. Use the following command to open the file with gedit:

sudo gedit /etc/php5/apache2/conf.d/xdebug.ini

Change the file so it looks like this:

; configuration for php xdebug module
zend_extension="/usr/lib/php5/20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Restart Apache
All left to do now is restart Apache with the following command:

sudo /etc/init.d/apache2 restart

Now you can check if all is OK with phpinfo(). You should see the following text:

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH

วิ่งอย่างไงให้ไวขึ้น

นักวิ่งเพื่อสุขภาพส่วนใหญ่แล้ว มีความคิดที่จะวิ่งออกกำลังกายให้สุขภาพแข็งแรง เพื่อการพักผ่อน และสนุกสนานเท่านั้น เมื่อมีผู้มาแนะนำว่า ให้ซ้อมวิ่งอย่างนี้ซิ จะพัฒนาการวิ่งให้ดีขึ้น นักวิ่งก็จะกลัวว่าจะเหนื่อย มีความยุ่งยากซับซ้อน มีกรรมวิธีมาก ไม่สามารถจะฝึกซ้อมได้ นักวิ่งเพื่อสุขภาพ เมื่อได้ไปทดลองวิ่งแข่งขัน ตามสนามวิ่งแข่งขัน ในปัจจุบัน จะได้เห็นนักวิ่งสุขภาพที่อายุมากกว่า หรืออายุรุ่นราวคราวเดียวกับนักวิ่ง วิ่งระยะทางเท่า ๆ กัน เกือบครึ่งหนึ่งของระยะทางทั้งหมด ทำไมเขาจึงทำได้ ท่านอยากพัฒนาการวิ่งให้เร็วขึ้นไหมล่ะ เสียเวลาอ่านข้อความ ที่จะแนะนำต่อไปนี้สักเล็กน้อย เราจะบอกวิธีฝึกเพิ่มความเร็วในการวิ่ง ซึ่งปราศจากข้อยุ่งยากในการปฏิบัต หนีความจำเจ จากการซ้อมวิ่งประจำวัน ไม่ต้องมีการบันทึกสถิติ ไม่มีการวัดการเต้นของหัวใจ จะพัฒนาการวิ่งของท่านให้เร็วขึ้น

อันดับแรก นักวิ่งที่เริ่มฝึกต้องสร้างความแข็งแกร่งของกล้ามเนื้อ เส้นเอ็นที่ยึดกระดูก และส่วนต่าง ๆ ของร่างกายให้รองรับความเค้น จะเกิดขึ้นจาการฝึกวิ่ง ต้องฝึกวิ่งประมาณ 12 สัปดาห์ ( 3 เดือน ) จนสามารถวิ่งเหยาะ ๆ ( จ๊อกกิ้ง ) ได้ระยะทาง 5 กม. โดยไม่หยุดเดิน 3-4 ครั้ง ใน 1 สัปดาห์ เมื่อร่างกายพร้อมแล้ว เรามาเริ่มฝึกกัน 3-4 วิธีดังนี้

การวิ่งจากจุดหนึ่งไปยังอีกจุดหนึ่งบนเส้นทางฝึกซ้อมวิ่ง ถ้าซ้อมวิ่งบนถนนจะมีความมั่นใจเมื่อลงสนามแข่งขัน โดย กำหนดที่หมายบนเส้นทางซ้อมวิ่งข้างหน้า อาจเป็นเสาไฟฟ้า รถยนต์ที่จอดอยู่ ตู้ไปรษณีย์ ต้นไม้ข้างทางเป็นต้น วิ่งไปยัง ที่หมายนั้นเร็วกว่า การวิ่งซ้อมปกติ เมื่อถึงที่หมายแล้ววิ่งเหยาะ (จ๊อกกิ้ง) เท่ากับระยะทางที่วิ่งเร็วมาสลับกันไป 6-8 เที่ยว

การวิ่งจับเวลาหรือนับก้าว โดยการซ้อมวิ่งเร็วกว่าการซ้อมวิ่งปกติ 15 วินาที สลับกับการวิ่งเหยาะ ( จ๊อกกิ้ง ) 40 วินาที หรือวิ่งนับก้าวประมาณ 60 ก้าว สลับกับการวิ่งเหยาะ ( จ๊อกกิ้ง ) ในระยะทางที่เท่ากัน ( ผู้แปล ได้ทดลองวัดระยะทาง ในการจับเวลา 15 วินาที และการนับก้าว 60 ก้าว ได้ระยะทางประมาณ 100 เมตร ) วิ่งสลับกันจำนวน 10 เที่ยว

ฝึกวิ่งขึ้นเนิน จะยากกว่าซ้อมวิ่งทางเรียบ น้ำหนักของร่างกายจะเป็นตัวต้านทานโดยธรรมชาติ นักวิ่งต้องใช้ความ พยายามให้มากขึ้น หาภูมิประเทศหรือสนามฝึกซ้อมวิ่งให้มีเนินซึ่งไม่สูงชันมาก ซ้อมวิ่งขึ้นเนินประมาณ เที่ยว 2 เที่ยว แรกวิ่งขึ้นเนินเที่ยวละ 45 วินาที 2 เที่ยว ต่อไปวิ่งขึ้นเนิน เที่ยวละ 30 วินาที 2 เที่ยว สุดท้ายวิ่งขึ้นเนินเที่ยวละ 15 วินาที หลังจากวิ่งขึ้นเนินแต่ละเที่ยว ให้วิ่งเหยาะ ( จ๊อกกิ้ง ) กลับเท่ากับระยะทางที่ใช้วิ่งขึ้นเนิน

วิ่งก้าวยาว ( Stride ) การวิ่งก้าวยาวจะแตกต่างจากการวิ่งจากจุดไปจุดหนึ่ง หรือการฝึกวิ่งขึ้นเนิน เพราะการฝึกวิ่งก้าวยาว จะทำให้กล้ามเนื้อแข็งแรง หัวใจและปอด ได้ทำงาน และเคยชินมากกว่า การซ้อมวิ่งชนิดอื่นๆ ที่กล่าวมา วิ่งก้าวยาวประมาณ 15 วินาที สลับกับการวิ่งเหยาะ ในระยะทางที่เท่ากัน จำนวน 10 เที่ยว

เมื่อนักวิ่งได้ทำการฝึกตามข้อแนะนำแล้วการพัฒนาการวิ่งจะเห็นผล เมื่อนักวิ่งได้ไปทดสอบการวิ่งในสนามการแข่งขันต่าง ๆ การพัฒนาการวิ่งหรือเวลาจะดีขึ้นก็อยู่ที่การฝึกซ้อมและได้ลงสนามแข่งขันบ่อย ๆ นักวิ่งจะเกิดความเคยชิน ควบคุมจังหวะการวิ่ง เวลาในการวิ่งได้ จะทำให้เกิดความสนุกสนานต่อการวิ่งเพื่อสุขภาพอย่างแท้จริง

ข้อแนะนำสำหรับผู้ที่เริ่มฝึกซ้อมพัฒนาการวิ่งให้เร็วขึ้น

เริ่มซ้อมวิ่งให้ร่างกายสร้างความเข้มแข็ง ประมาณ 12 สัปดาห์ ( 3 เดือน ) สามารถวิ่งเหยาะได้ 30 นาที โดยไม่หยุดพัก 3 - 4 ครั้งใน 1 สัปดาห์

หลีกเลี่ยงเส้นทางที่มีจราจรคับคั่ง มีสิ่งกีดขวาง เช่น รากไม้ รอยแตก เส้นทางที่เป็นหลุมเป็นบ่อ และเส้นทางที่ลาดลงยาว ๆ จะทำให้เร่งความเร็วกล้ามเนื้อบาดเจ็บได้

เส้นทางซ้อมวิ่งถ้าเป็นสนามหญ้า หรือทางดินจะเป็นสนามซ้อมวิ่งดี

สนามที่มียางสังเคราะห์จะดีที่สุด เพราะมีแรงส่งด้วย

เส้นทางที่ราดด้วยแอสฟัลส์ดิคพอใช้ได้

เส้นทางที่ราดด้วยปูนซีเมนต์ ให้ระมัดระวังการบาดเจ็บควรหลีกเลี่ยงในการฝึกซ้อม พัฒนาความเร็ว

ก่อนเริ่มฝึกซ้อมควรอบอุ่นร่างกายก่อน 10 -15 นาที ด้วยการวิ่งเหยาะ และยืดกล้ามเนื้อ หลังฝึกซ้อมควร คูลดานัว และยืดกล้ามเนื้อประมาณ 5-10 นาที จะลดอาการบาดเจ็บ และอ่อนเพลียจากการฝึกซ้อมได้

อย่าเริ่มฝึกซ้อมโดยทันที โดยไม่อบอุ่นร่างกายและยืดกล้ามเนื้อก่อนจะทำให้ระบบหัวใจ และกล้ามเนื้อทำงานไม่ทัน อาจเกิดอาการบาดเจ็บจากการฝึกซ้อมได้

ใน 1 สัปดาห์ ควรฝึกซ้อมพัฒนาการวิ่งอย่างใดอย่างหนึ่งอย่างน้อย 1 ครั้ง และไม่เกิน 2 ครั้งต่อสัปดาห์ หลังการฝึกซ้อมควรพัก 1 วัน สามารถวิ่งเหยาะได้

เมื่อแข่งขันอย่าออกตัวด้วยความเร็วที่เคยฝึกซ้อมมา เพราะระยะทางที่ใช้ในการแข่งขันนั้น มากกว่าที่เราฝึกซ้อมมากนัก นักวิ่งจะเกิดการการชนกำแพงไม่ถึงที่หมาย ให้วิ่งอย่าง สบาย ควบคุมจังหวะการวิ่งให้ครบระยะทางที่กำหนด

ประการสุดท้าย การฝึกซ้อมพัฒนาการวิ่งให้เร็วขึ้น จะไม่เห็นผลในทันทีทันใด ต้องใช้ระยะเวลาพอสมควร เมื่อถึงเวลานั้น นักวิ่งจะสังเกตได้ ท่านจะซ้อมวิ่งทุกวัน ได้อย่างง่าย ไม่เหนื่อยเหมือนเมื่อก่อน เกิดความสนุก ในการฝึกซ้อมวิ่ง ที่มีความสนุก ในการเข้าร่วมแข่งขัน นักวิ่งสามารถพัฒนาการวิ่งให้ดีขึ้นอีก จากการเพิ่มระยะทาง เพิ่มเวลาในการฝึกซ้อม ประสบการณ์ จะช่วยนักวิ่งได้ดีที่สุด

วันอังคารที่ 5 เมษายน พ.ศ. 2554

mount usb 2 on blacktack

1. Example

2. Detecting USB hard drive

After you plug in your USB device to your USB port, linux will add new block device into /dev/ directory. At this stage you are not able to use this device as the USB filesystem needs to be mouted before you are able to retrieve any data. To find out what name your block device file have you can run fdisk command:

# fdisk -l

You will get output similar to this:

Disk /dev/sdb: 60.0 GB, 60060155904 bytes
255 heads, 63 sectors/track, 7301 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b2b03

Device Boot Start End Blocks Id System
/dev/sdb1 1 7301 58645251 b W95 FAT32


3. Creating mount point

Create directory where you want to mount your device:

mkdir /mnt/sdb1

4. Edit /etc/fstab

To automate this process you can edit /etc/fstab file and add line similar to this:

/dev/sdb1 /mnt/sdb1 vfat defaults 0 0

Run mount command to mount all not yet mounted devices. Keep in mind that if you have more different USB devices in you system, device name can vary!!!

# mount -a

mount on ubuntu

This page explains how to use USB drives, like external hard disks and USB flash drives (aka USB sticks, thumb drives, pen drives, etc). The material here also applies to flash cards (like in your digital camera).

IconsPage/stop.png If you are looking for help with internal hard drives, see these links:

*

Fstab
*

MountingWindowsPartitions

IconsPage/IconTip.png USB storage devices have the enormous advantage that for the most part they use a standard set of protocols. Thus, instead of needing individual drivers, as does much computer hardware, a standard driver permits access to the devices, making them very portable and able to easily work on many platforms.

Automounting

Mounting

By default, storage devices that are plugged into the system mount automatically in the /media directory, open a file browser window for each volume and place an icon on your desktop. If you plug in a usb hard disk with many partitions, all of the partitions will automatically mount. This behaviour may not be what you want so you can configure it as shown below.

If the volumes have labels the icons will be named accordingly, otherwise they will be named "disk" and as more volumes are added, you can get "disk-1" and so on.

To change the volume label see RenameUSBDrive.

Configuring Automounting

To enable or disable automount open a terminal and type gconf-editor followed by the [Enter] key.

Browse to /apps/nautilus/preferences/media_automount.

The media_automount key controls whether to automatically mount media. If set to true, then Nautilus will automatically mount media such as user-visible hard disks and removable media on start-up and media insertion.

There is another key /apps/nautilus/preferences/media_automount_open. This controls whether to automatically open a folder for automounted media. This key can also be set in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab.

If set to true, then Nautilus will automatically open a folder when media is automounted. This only applies to media where no known x-content/* type was detected; for media where a known x-content type is detected, the user configurable action will be taken instead. This can be configured as shown below.

Configuring Program Autostart

To control which programs automatically start when you plug in a device, go to System->Preferences->Removable Drives and Media.

Ubuntu 9.10 (Karmic Koala)

In Ubuntu 9.10 (Karmic Koala) Removable Drives and Media is no longer in the Preferences menu but you can still do this as follows.

This user configurable action for specific media types can be configured in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab. There you can select what happens when media is inserted. For example we need to turnoff audio CD auto play. CD audio "can do nothing" or "ask what to do" or "open folder".

For more complex scenarios, see UsbDriveDoSomethingHowto.

Unmounting/Ejecting

Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject"). In Ubuntu 9.10 (Karmic Koala), in the file manager window you can also click on an "eject" button against the name of the mounted volume.

Automounting (Ubuntu Server)

By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount".

Manually Mounting

Using mount

Get the Information

IconsPage/IconGNOMETerminal.png Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS.

sudo fdisk -l

Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see LinuxFilesystemsExplained.

Create the Mount Point

Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point:

sudo mkdir /media/external

Mount the Drive

IconsPage/example.png We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):

sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137

The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you may not be able to read and write the drive with your regular username.

Otherwise if the device is formatted with NTFS, run:

sudo mount -t ntfs-3g /dev/sdb1 /media/external

IconsPage/IconNote.png You must have the ntfs-3g driver installed. See MountingWindowsPartitions for more information.

Unmounting the Drive

IconsPage/example.png When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point:

sudo umount /dev/sdb1

or:

sudo umount /media/external

You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted.

Using pmount

There is a program called pmount available in the repositories which allows unprivileged users to mount drives as if they were using sudo, even without an entry in /etc/fstab. This is perfect for computers that have users without RootSudo access, like public terminals or thin clients.

pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows:

pmount [ label ]

Example:

*

pmount /dev/sdb1 flash_drive

This will mount the device /dev/sdb1 at /media/flash_drive

If you leave off the label option, it will mount by default at /media/device

To unmount the device, use pumount, like so:

pumount

Example:

*

pumount /dev/sdb1

For more help, you can see the man pages for pmount and pumount.

Unmounting Explained

IconsPage/IconHint2.png Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares.

Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them!

Other Useful Commands

To see a list of your USB devices (the vendor and device ID's), run:

lsusb

To see all attached storage devices and their partitions, run:

sudo fdisk -l

To see information about currently mounted systems, simply run:

mount

Troubleshooting

Presented here are some common problems users encounter.

Unclean LogFile

If you are mounting drives formatted with NTFS (like most external USB hard disks are), you must first have the ntfs-3g driver installed. This is done automatically in newer versions of Ubuntu. You should also install ntfs-config and enable the mounting, which is not done automatically. For ntfs-3g and ntfs-config, see MountingWindowsPartitions.

IconsPage/IconFAQ.png When a drive is not Safely Removed from a Windows machine (or a forced shutdown occurs from Windows), you may get an error like this when you plug in your drive:

$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/sda1': Operation not supported
Mount is denied because NTFS is marked to be in use. Choose one action:

Choice 1: If you have Windows then disconnect the external devices by
clicking on the 'Safely Remove Hardware' icon in the Windows
taskbar then shutdown Windows cleanly.

Choice 2: If you don't have Windows then you can use the 'force' option for
your own responsibility. For example type on the command line:

mount -t ntfs-3g /dev/sda1 /media/sda1/ -o force

The best option is Choice 1, but you can force the mount by running Choice 2 with sudo. Then to unmount the drive, you must do it manually from terminal (you can't right click the desktop icon):

sudo umount

After that the drive should automount normally again.

User Privileges

If your usb device doesn't appear on your desktop, you should check that your user has the correct privileges. Go to System->Administration->User and Groups, choose the user, click on "Properties", then go to the "User Privileges" tab. You should have the "Access external storage devices automatically" option checked.

Preferences

If your usb device doesn't appear on your desktop, you should check that the automount action is enabled in the preferences:

*

Navigate to "System" > "Preferences" > "Removable Drives and Media"
* Verify that all "Mount removable drives when..." are checked.

NOTE: This does not seem to apply to Hardy Heron.

USB 2 Issues

old kernels workaround

If you encounter problems using your USB device with USB 2 (i.e. 'high speed' mode), you can revert to the 'full speed' mode (slower) by unloading ehci_hcd. To do that, type in a terminal:

sudo rmmod ehci_hcd

before plugging in your device.

recent kernels workaround, from Karmic

see also AbsolutelyTech

ehci_hcd is now built into the kernel and cannot be load/unloaded using modprobe. To revert a connected device from (failing) high-speed to full-speed.

1) identify your device id using

lsusb

2) find to which bus it is connected. The bus id can be found as a folder in /sys/bus/pci/drivers/ehci_hcd. Below script explores buses and connected devices.

pushd /sys/bus/pci/drivers/ehci_hcd > /dev/null
for bus in 0000:??:??.? ; do
echo "ehci_hcd bus $bus"
pushd $bus/usb1 > /dev/null
for dev in ?-?; do
idVendor=`cat $dev/idVendor`
idProduct=`cat $dev/idProduct`
echo "ehci_hcd bus $bus: device $dev = $idVendor:$idProduct"
done
popd > /dev/null
done
popd > /dev/null

The information is also usually available in /var/log/kern.log 3) Unbind the bus (and all devices) from the ehci_hcd driver. replace in below code the bus id, which format is 0000:00:xx.x

sudo sh -c 'echo -n "0000:00:xx.x" > unbind'

Buffer I/O Errors

If you see errors related to Buffer I/O when attaching a USB Storage device, there are two ways to work around it. First, try using varying max_sectors settings, as such:

sudo sh -c "echo 120 > /sys/block/sda/queue/max_sectors_kb"

Try values of 120, 64 and 32.

If this does not resolve the issue, then you may need an unusual_dev entry for your device. It would look something like this:

UNUSUAL_DEV(0x03eb , 0x2002, 0x0100, 0x9999,
"Generic",
"MusicDrive",
US_SC_DEVICE, US_PR_DEVICE, NULL,
US_FL_IGNORE_RESIDUE),

The vendor and device ID's can be obtained from the output of "lsusb". The entry would be placed in drivers/usb/storage/unusual_devs.h. If you cannot compile your own kernel, please file a bug report, and we'll attempt to compile a test module for you.

Device become suddenly read only

If your device changes suddenly to read only mode, and you see this kind of error:

[17183798.908000] FAT: Filesystem panic (dev sda1)
[17183798.908000] fat_get_cluster: invalid cluster chain (i_pos 0)
[17183798.908000] File system has been set read-only

This might be the sign of an unclean device. You should check your device. Try TestingStorageMedia to do so. Or use "Disk Utility" (under System, Administration), find your device, unmount it, check the file system, then mount it again.

USB-Device is, or become suddenly read only without errors

If you see "Write Protect is off" and no errors in your logfiles, than you should set filesystem type specific mount options (FS_MOUNTOPTIONS) in /etc/usbmount/usbmount.conf. Wrong gid causes mounting read only.

General tip

When you encounter problems with USB devices, the first thing to do is to check the latest debug information generated from the kernel just after you plug in your device and/or just after you encounter the problem.
To do that, open a terminal and type :

dmesg

Check the latest messages, they should be related to your problem.

Seeking Further Help

The best place to get help with almost any Ubuntu problem is on the Ubuntu Forums. The Absolute Beginner Talk section is best for beginners.