Showing posts with label Freebsd. Show all posts
Showing posts with label Freebsd. Show all posts

Thursday, July 28, 2011

Nano Basics Guide

Nano Basics Guide
1.  Nano Basics
Purpose
          This guide was written to cover basic operations in nano, and is meant to be very concise. For more information about nano check out:

Opening and creating files
Opening and creating files is simple in nano, simply type:

Code Listing 1.1: Creating or opening a file
# nano filename

         Nano is a modeless editor so you can start typing immediately to insert text. If you are editing a configuration file like /etc/fstab use the -w switch, for example:

Code Listing 1.2: Disable the word wrapping
# nano -w /etc/fstab

Warning: It is very, very important that you use the -w switch when opening a config file. Failure to do so may keep your system from booting or cause other bad things.

Saving and exiting
           If you want to save the changes you've made, press Ctrl+O. To exit nano, type Ctrl+X. If you ask nano to exit from a modified file, it will ask you if you want to save it. Just press N in case you don't, or Y in case you do. It will then ask you for a filename. Just type it in and press Enter.

          If you accidentally confirmed that you want to save the file but you actually don't, you can always cancel by pressing Ctrl+C when you're prompted for a filename.

Cutting and pasting
          To cut a single line, you use Ctrl+K (hold down Ctrl and then press K). The line disappears. To paste it, you simply move the cursor to where you want to paste it and punch Ctrl+U. The line reappears. To move multiple lines, simply cut them with several Ctrl+Ks in a row, then paste them with a single Ctrl+U. The whole paragraph appears wherever you want it.

          If you need a little more fine-grained control, then you have to mark the text. Move the cursor to the beginning of the text you want to cut. HitCtrl+6 (or Alt+A). Now move your cursor to the end of the text you want to cut: the marked text gets highlighted. If you need to cancel your text marking, simply hit Ctrl+6 again. Press Ctrl+K to cut the marked text. Use Ctrl+U to paste it.

Searching for text
         Searching for a string is easy as long as you think "WhereIs" instead of "Search". Simply hit Ctrl+W, type in your search string, and press Enter. To search for the same string again, hit Alt+W.

Note: In nano's help texts the Ctrl-key is represented by a caret (^), so Ctrl+W is shown as ^W, and so on. The Alt-key is represented by an M (from "Meta"), so Alt+W is shown as M-W.

More options
       If you're interested in tweaking nano, be sure to read /etc/nanorc.

Wrap up
       That is all! Thanks to kiyose and quazion from #gentoo. Again, for more information about nano check out: http://www.nano-editor.org

ติดตั้งโปรแกรม nano บน FreeBSD ง่ายๆผ่าน port กันหน่อยไหม

วันนี้มาดูวิธีการติดตั้งโปรแกรมผ่านทาง FreeBSD Ports Collection กัน โดยโปรแกรมที่ผมจะใช้เป็นตัวอย่างในการทดลองครั้งนี้ก็จะเป็น nano นะครับ ซึ่ง nano เป็นโปรแกรม text editor ที่ใช้งานง่ายตัวหนึง สำหรับคนที่ไม่ถนัด vi ผมก็แนะนำให้ใช้ nano นี้แทนไปเลยนะครับง่ายดี
การติดตั้งโปรแกรมผ่านทาง FreeBSD Ports Collection เป็นวิธีที่เราสามารถติดตั้งโปรแกรมได้อย่างง่ายดาย และก็มีโปรแกรมต่างๆ ที่ทาง FreeBSD เค้าได้เตรียมไว้ให้เราอยู่แล้ว โดยจุดเด่นของการติดตั้งโปรแกรมผ่านทาง Ports Collection ก็คือความสามารถในการ download โปรแกรมที่เกี่ยวข้องกับโปรแกรมที่เราจะทำการติดตั้งมาให้เอง โดยที่เราแทบไม่ต้องทำอะไรเลย ต่อไปเราจะได้มาดูกันว่ามันง่ายแค่ไหน
ก่อนการติดตั้งโปรแกรมจาก FreeBSD Ports Collection ให้เราทำการติดตั้ง FreeBSD Ports Collection ก่อนนะครับ ซึ่งดูได้จากบทความที่แล้ว ซึ่งหลังจากติดตั้ง FreeBSD Ports Collection เรียบร้อยแล้วให้ตรวจสอบการ connect internet ด้วยนะครับว่าสามารถใช้งานได้ปกติหรือไม่ เพราะว่าการติดตั้งผ่านทาง Ports Collection ระบบจะต้องทำการ download source ของโปรแกรมต่างๆที่จะติดตั้งมาจาก internet นะครับ
มาดูกันต่อเลยครับ อย่างแรกให้เข้าไปที่ /usr/ports/
# cd /usr/ports/
# ls
จะเห็นว่ามีการแบ่งเป็น directory ของโปรแกรมในกลุ่มต่างๆอย่างเป็นระบบ
ที นี้หลายคนคงจะคิดว่า แล้วเราจะไปหาเจอไหมว่าโปรแกรมที่เราต้องการจะติดตั้งมันอยู่ที่ไหนละ เรื่องนั้นทาง FreeBSD เค้าได้เตรียมเครื่องมือไว้ให้เราอยู่แล้วครับ นั้นก็คือ whereis โดยมีรูปแบบการใช้งานดังนี้ “whereis ProgramName”
# whereis nano
nano : /usr/ports/editors/nano
จะเห็นว่าเมื่อเราสั่ง whereis เราก็จะทราบว่า โปรแกรม nano อยู่ที่ไหน เมื่อได้ path ที่ของโปแกรมใน Ports Collection มาแล้ว ทีนี้เราก็มาติดตั้งกันเลย
# cd /usr/ports/editors/nano
# make install clean



ระบบกำลังทำการ download โปรแกรม nano เพื่อทำการติดตั้ง รอสักครู่…



ระบบจะแจ้งให้ทราบว่า nano จำเป็นจะต้องใช้ library ของ gettext ด้วย ซึ่งจะมี options ต่างๆให้เลือกด้วยว่าจะติดตั้งด้วยหรือไม่ ในที่นี้ไม่ต้องเลือกอะไรนะครับให้กด OK ไปได้เลย จากนั้นระบบจะทำการ download gettext และ library ที่เกี่ยวข้องอื่นๆ ทั้งหมด กรุณารอสักครู่……
เมื่อทำการ download source ของโปรแกรมต่างๆเรียบร้อยแล้ว ระบบจะทำการ compile โปรแกรมต่างๆให้เอง โดยที่เราไม่ต้องทำอะไรเลย
ช่วงนี้ก็ ส่ง sms ไปบอกคิดถึงแฟนก่อนได้เลย ^_^
จาก นั้นเมื่อโปรแกรมต่างๆถูก compile เรียบร้อยแล้ว เราก็สามารถเรียกใช้งาน nano ได้เลยครับ (หากว่าใครลองเรียกใช้งาน nano แล้ว ไม่สามารถใช้งานได้ ให้ทำการ logout ออกจาก shell แล้วทำการ login เข้ามาใหม่นะครับ จากนั้นให้เรียกใช้ nano อีกครั้ง เพียงแค่นี้ก็ใช้งานได้แล้วครับ)
# nano


หน้าตาโปรแกรมของ nano
เพียงเท่านี้เราก็ได้โปรแกรมที่ต้องการไว้ใช้งานแล้ว ต่อไปเวลาที่จะทำการแก้ไข text file ต่างๆเราก็ใช้ nano แทน vi ได้เลยครับ
แต่ ถ้าหากว่าเราทำการติดตั้งโปแกรมอะไรลงไปแล้ว ต้องการที่จะ uninstall โปรแกรมนั้นๆออกก็สามารถทำได้ง่ายๆ โดยใช้ make deinstall clean
# cd /usr/ports/editors/nano
# make deinstall clean

เปลี่ยนรหัสผ่าน root สำหรับ FreeBSD



เมื่ออาจเจอเหตุการณ์ที่ลืมรหัสผ่าน root สำหรับ FreeBSD สามารถตั้งรหัสผ่านใหม่ได้ โดยวิธีดังนี้
ขั้นตอนที่ 1 บูตเข้าระบบตามปกติ เมื่อปรากฏหน้าจอดังภาพ ให้เลือกตัวเลือกที่ 4 – Boot FreeBSD in single Mode
ขั้นตอนที่ 2 ระบบจะโหลดค่าต่างๆ จนเข้ามาที่ Path : /bin/sh ดังภาพ
ขั้นตอนที่ 3 ยกเลิก เพื่อออกจาก Path นั้น โดยใช้คำสั่ง

ขั้นตอนที่ 4 จะเข้ามาที่พร้อม # สามารถ mount path ใหม่ได้ (ถ้าต้องการ) โดยใช้คำสั่ง
หลังจากนั้นเราสามารถเปลี่ยนรหัสผ่านของ root โดยใช้คำสั่ง




ระบบจะให้พิมพ์รหัสผ่านใหม่ ซึ่งต้องพิมพ์ให้เหมือนกันทั้งสองครั้งเพื่อเป็นการยืนยันความถูกต้องของรหัสผ่าน
หลังจากนั้นการเปลี่ยนรหัสผ่านให้ root ก็เรียบร้อย เราสามารถ Reboot เพื่อเข้าระบบใหม่อีกครั้งด้วยคำสั่ง