Labels

Linux (46) network (13) troubleshoot (13) command (10) virtualization (10) ubuntu (9) Windows (8) cisco (7) security (7) router (6) Tools (5) software (5) vmware (5) ospf (3) eigrp (1) zimbra (1)

2010年1月29日

Recommended application and installation for new Ubuntu user

For those just finished the system installation, please look below:

1. Setup input method:
go System>administration>language support>install/remove languages then choose what you want.

2. Compiz fusion - using simple-ccsm:
open terminal, execute the command "apt-get install simple-ccsm"

3. Google desktop:
You can download and install the plugin on your desktop.
http://desktop.google.com/plugins/


4. Virtual box
http://www.virtualbox.org/wiki/Linux_Downloads

5. vmserver
http://register.vmware.com/content/download.html

...to be continuous

2010年1月27日

Linux - Compression and Uncompression Example

compress
compress bigfile     <--------- compress bigfile to be bigfile.Z, bigfile will be disappear.
compress -r myfolder     <---------compress all file to be .Z file in myfolder
compress -c bigfile     <---------display the result to stdout
compress -c bigfile > smallfile.Z      <---------by which, unchange bigfile but saveas another compressed file(smallfile.Z).

uncompress
uncompress smallfile.Z

gzip
gzip bigfile     <--------- compress bigfile to be bigfile.gz
gzip -9 bigfile     <--------- compress bigfile to be bigfile.gz, -9 is best quality but slowest, -1 is the fastest but low compress, default is -6.
gzip -c bigfile > smallfile.gz      <--------- unchange bigfile but save as another compressed file(smallfile.gz).

gunzip
gunzip smallfile.gz     <--------- extract the gz file
gunzip -c smallfile.gz > file     <--------- extract smallfile.gz to a file,and don't smallfile.gz

zcat

zcat smallfile.gz     <---------see the file content without unzip

bzip2, bunzip2, bzcat

bzip2 default compress level 2
the usage is like gzip, gunzip, zcat
(Hints: gzip is better than compress, bzip2 is the best)

2010年1月20日

Change process priority - nice and renice

Nice number
• Range: -20 ~ +19
• User process default: 0
• + no. lower the priority
• - no. raise the priority
• Only root can lower the no.
• Don’t assign +no. to fg jobs -- sluggish

Syntax
• Just nice shows current priority
• nice [-n no.] [command]
• nice [-no.] [command]
• Normal user: no. = 1~19
• Root: no. = -20~19
• Not specified no.: default to 10

Examples

[law@localhost ~]$ nice seq 1000000&
Using default nice# 10 to reduce priority

[law@localhost ~]$ nice -n -10 vi /etc/hosts.deny
Start vi at high priority (-10)

renice
Modify nice no. of a running program
Syntax:
Renice [+|-]nicenumber [option] targets

Examples
[law@localhost ~]$ renice 19 501
 Lower process 501's priority
[law@localhost ~]$ renice -10 -u law -p 501
 Increase all law's process and process 501

Checking system status

ps aux             <----show all process
ps auxf             <----show all process as tree format
ps a -l             <----here -l means long format, see detail

pstree             <----show process as tree format
pstree -p             <----display with pid
pstree -H 1974             <----high light the 1974 process

top
top -d 2             <----Change data with 2 second.
top -b -n 2 > /home/ray/topresult     <----run top 2 times and redirect the result to a file
in top interface:
press q is exit
press M is sort by memory
press < or > means sort by previous or next column


free -m              <----Check memory status

netstat -ntlp             <----Show the network status, here "l" means those listening process

vmstat 2             <----Check CPU status, take snapshot with 2 seconds
vmstat 2 4            <----Check CPU status, take snapshot with 2 seconds and do it 4 times
vmstat -d               <----Show disk read write status

df -h               <----Show harddisk space size

runlevel               <----Show previous and current runlevel

2010年1月19日

Linux command - cut, sed, awk

Cut

cut -c 1-7 f1 will output the first 7 characters in each line of file 'f1'.

cut -c 2,4-7,10- f1 will output the character 2, characters 4 – 7, characters 10 until the end of line in each line of file 'f1'.

cut -f 1,4,5 f1 will output 'fields' 1, 4 and 5 in file 'f1'. The fields are assumed to be separated by tab in 'f1'.

cut -d ' ' -f 1,4,5 f1 will output 'fields' 1, 4 and 5 in file 'f1'. The fields are assumed to be separated by a single space in 'f1'.

Sed

Let's make a test file
ls -l /etc > testsed

"d" means delete
sed '1,4d' testsed
sed '/yum/d' testsed
sed '/yum/!d' testsed

"s" is replace, -n means hide the other output, p is display
sed -n 's/pass/xxxxx/p' testsed


Awk
Make another file to test awk
ps aux > testawk

Show column 11
awk '{print $11}' testawk

awk '/sbin/{print $2,$11}' testawk

2010年1月18日

ps aux 各欄位的意義

在 ps aux 顯示的項目中,各欄位的意義為:

* USER:該 process 屬於那個使用者帳號的?
* PID :該 process 的程序識別碼。
* %CPU:該 process 使用掉的 CPU 資源百分比;
* %MEM:該 process 所佔用的實體記憶體百分比;
* VSZ :該 process 使用掉的虛擬記憶體量 (Kbytes)
* RSS :該 process 佔用的固定的記憶體量 (Kbytes)
* TTY :該 process 是在那個終端機上面運作,若與終端機無關則顯示 ?,另外, tty1-tty6 是本機上面的登入者程序,若為 pts/0 等等的,則表示為由網路連接進主機的程序。
* STAT:該程序目前的狀態,狀態顯示與 ps -l 的 S 旗標相同 (R/S/T/Z)
* START:該 process 被觸發啟動的時間;
* TIME :該 process 實際使用 CPU 運作的時間。
* COMMAND:該程序的實際指令為何?

Fine tune your VM - Extend vm disk size in Linux

Step1: Login with admin, shutdown your PC

Step2: Eg: Extend your vm to 40GB
vmware-vdiskmanager -x 40GB winxp.vmdk
Then your disk space would be expanded, but the free space is not assigned to your system.

Step3: List your registered vm, check the ID
vmware-vim-cmd vmsvc/getallvms

Step4: Poweron your vm
vmware-vim-cmd vmsvc/power.on 96

Step5: If you the vm is windows, then go to computer manager to assign the free space to C: or D: as you like.
To expand system driver (such as C: which holding winxp) then you may need to do it with thrid party partition tools. Here you can get more information: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1004071

2010年1月10日

Fedora 12 enable root login in GUI

1. edit /etc/pam.d/gdm and /etc/pam.d/gdm-password
2. Add comment(#) to the following line
# auth required pam_succeed_if.so user != root quiet

2010年1月7日

editor - vi

.vi 的操作模式
==============
        vi 提供兩種操作模式:輸入模式(insert mode)和指令模式(command mode)
        。當使用者進入 vi 後,即處在指令模式下,此刻鍵入之任何字元皆被視為
        指令。在此模式下可進行刪除、修改等動作。若要輸入資料,則需進入輸入
        模式。

.輸入模式
=========
        如何進入輸入模式
                a (append)      由游標之後加入資料。
                A               由該行之末加入資料。
                i (insert)      由游標之前加入資料。
                I               由該行之首加入資料。
                o (open)        新增一行於該行之下供輸入資料之用。
                O               新增一行於該行之上供輸入資料之用。

如何離開輸入模式
                《ESC》 結束輸入模式。

.指令模式
=========
游標之移動
        h       向左移一個字元。
        j       向上移一個字元。
        k       向下移一個字元。
        l       向右移一個字元。
        0       移至該行之首
        $       移至該行之末。
        ^       移至該行的第一個字元處。
        H       移至視窗的第一列。
        M       移至視窗的中間那列。
        L       移至視窗的最後一列。
        G       移至該檔案的最後一列。
        +       移至下一列的第一個字元處。
        -       移至上一列的第一個字元處。
        (       移至該句之首。 (註一)
        )       移至該句之末。
        {       移至該段落之首。 (註二)
        }       移至該段落之末。
        nG      移至該檔案的第 n 列。
        n+      移至游標所在位置之後的第 n 列。
        n-      移至游標所在位置之前的第 n 列。
        <Ctrl><g>       會顯示該行之行號、檔案名稱、檔案中最末行之行號、游標
                        所在行號佔總行號之百分比。

註一:句子(sentence)在vi中是指以『!』、『.』或『?』結束的一串字。
        註二:段落(paragraph)在vi中是指以空白行隔開的文字。

.視窗的移動
===========
        <Ctrl><f>       視窗往下捲一頁。
        <Ctrl><b>       視窗往上捲一頁。
        <Ctrl><d>       視窗往下捲半頁。
        <Ctrl><u>       視窗往上捲半頁。
        <Ctrl><e>       視窗往下捲一行。
        <Ctrl><y>       視窗往上捲一行。

.刪除、複製及修改指令介紹 (此單元較少使用)
=========================
        d(delete)、c(change)和y(yank)這一類的指令在 vi 中的指令格式為:
        Operator + Scope = command
        (運算子)   (範圍)
        運算子:
        d       刪除指令。刪除資料,但會將刪除資料複製到記憶體緩衝區。
        y       將資料(字組、行列、句子或段落)複製到緩衝區。
        p       放置(put)指令,與 d 和 y 配和使用。可將最後delete或yank的資
                料放置於游標所在位置之行列下。
        c       修改(change)指令,類似delete與insert的組和。刪除一個字組、句
                子等之資料,並插入新鍵資料。

範圍:
        e       由游標所在位置至該字串的最後一個字元。
        w       由游標所在位置至下一個字串的第一個字元。
        b       由游標所在位置至前一個字串的第一個字元。
        $       由游標所在位置至該行的最後一個字元。
        0       由游標所在位置至該行的第一個字元。
        )       由游標所在位置至下一個句子的第一個字元。
        (       由游標所在位置至該句子的第一個字元。
        {       由游標所在位置至該段落的最後一個字元。
        }       由游標所在位置至該段落的第一個字元。

整行動作
        dd      刪除整行。
        D       以行為單位,刪除游標後之所有字元。
        cc      修改整行的內容。
        yy      yank整行,使游標所在該行複製到記憶體緩衝區。

.刪除與修改
===========
        x       刪除游標所在該字元。
        X       刪除游標所在之前一字元。
        dd      刪除游標所在該行。
        r       用接於此指令之後的字元取代(replace)游標所在字元。
                如: ra 將游標所在字元以 a 取代之。
        R       進入取代狀態,直到《ESC》為止。
        s       刪除游標所在之字元,並進入輸入模式直到《ESC》。
        S       刪除游標所在之該行資料,並進入輸入模式直到《ESC》。

.搬移與複製
==========
        利用 delete 及 put 指令可完成資料搬移之目的。
        利用 yank 及 put 指令可完成資料複製之目的。
        yank 和 delete 可將指定的資料複製到記憶體緩衝區,而藉由 put 指令
        可將緩衝區內的資料複製到螢幕上。
        例:
        搬移一行        ‧在該行執行 dd
                        ‧游標移至目的地
                        ‧執行 p
        複製一行        ‧在該行執行 yy
                        ‧游標移至目的地
                        ‧執行 p

.指令重複
=========
        在指令模式中,可在指令前面加入一數字 n,則此指令動作會重複執行 n
        次。
        例:
        刪除10行                ‧10dd
        複製10行                ‧10yy
                                ‧游標移至目的地
                                ‧p
        指標往下移10行  ‧10j

.取消前一動作(Undo)
===================
        即復原執行上一指令前的內容。

u       恢復最後一個指令之前的結果。
        U       恢復游標該行之所有改變。

.搜尋
=====
        在vi中可搜尋某一字串,使游標移至該處。

/字串           往游標之後尋找該字串。
        ?字串           往游標之前尋找該字串。
        n               往下繼續尋找下一個相同的字串。
        N               往上繼續尋找下一個相同的字串。

.資料的連接
===========
        J       句子的連接。將游標所在之下一行連接至游標該行的後面。

若某行資料太長亦可將其分成兩行,只要將游標移至分開點,進入輸入模式
        (可利用 a、i等指令)再按《Enter》即可。

.環境的設定
===========
        :set nu                設定資料的行號。
        :set nonu              取消行號設定。
        :set ai                自動內縮。
        :set noai              取消自動內縮。

自動內縮(automatic indentation)
        在編輯文件或程式時,有時會遇到需要內縮的狀況,『:set ai』即提供自
        動內縮的功能,用下例解釋之:
        ‧vi test
        ‧(進入編輯視窗後)
          this is the test for auto indent
          《Tab》start indent           ← :set ai (設自動內縮)
          《Tab》data
          《Tab》data
          《Tab》data                   ← :set noai (取消自動內縮)
        the end of auto indent.
        ‧註:<Ctrl><d> 可刪除《Tab》字元。

.ex指令
=======
        讀寫資料
        :w                     將緩衝區的資料寫入磁碟中。
        :10,20w test   將第10行至第20行的資料寫入test檔案。
        :10,20w>>test  將第10行至第20行的資料加在test檔案之後。
        :r test                將test檔案的資料讀入編輯緩衝區的最後。

刪除、複製及搬移
        :10,20d                刪除第10行至第20行的資料。
        :10d                   刪除第10行的資料。
        :%d                    刪除整個編輯緩衝區。
        :10,20co30             將第10行至第20行的資料複製至第30行之後。
        :10,20mo30             將第10行至第20行的資料搬移至第30行之後。

字串搜尋與取代
        s(substitute)指令可搜尋某行列範圍。
        g(global)指令則可搜尋整個編輯緩衝區的資料。
        s指令以第一個滿足該條件的字串為其取代的對象,若該行有數個滿足該條
        件的字串,也僅能取代第一個,若想取代所有的字串則需加上g參數。
        :1,$s/old/new/g                將檔案中所有的『old』改成『new』。
        :10,20s/^/   /         將第10行至第20行資料的最前面插入5個空白。
        :%s/old/new/g          將編輯緩衝區中所有的『old』改成『new』。

.恢復編輯時被中斷的檔案
=======================
        在編輯過程中,若系統當掉或連線中斷,而緩衝區的資料並還未
        被寫回磁碟時,當再度回到系統,執行下列指令即可回復中斷前
        的檔案內容。
        %vi -r filename

.編輯多個檔案
=============
        vi亦提供同時編輯多個檔案的功能,方法如下:
        %vi file1 file2 ..

當第一個檔案編修完成後,可利用『:w』將該緩衝區存檔,而後
        再利用 『:n』載入下一個檔案。