發表文章

Linux Process

什麼是Process 程序是一段指令的集合,被載入記憶體 使用 Numeric Process ID (PID) 識別程序 UID, GID and SELinux context 決定 filesystem 存取 Normally 繼承 from the 執行者 列出 Process View Process information with ps [lcc09@localhost ~]$ ps --help ********* simple selection ********* ********* selection by list ********* -A 所有的程序 -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session leaders -U by real user ID (supports names) -d all except session leaders -g by session OR by effective group name -e all processes -p by process ID T all processes on this terminal -s processes in the sessions given a all w/ tty, including other users -t by tty g OBSOLETE -- DO NOT USE -u by effective user ID (supports names) r only running processes U processes for specified users x 把包含不被ttys控制的程序都列出來 *********** output format ********** *********** long options *******...

Linux 編輯器

圖片
編輯器 linux上的編輯器有很多種 emacs gedit nano 大致分成兩類: 命令列模式Command line editors 圖形介面Graphical editors VI(VIM) 官方網站  http://www.vim.org/ vi 為 標準unix的文字編輯器,可以使用 vi 或 vim 執行 gvim 是圖形介面版的 vim 應用程式+程式設計 = Vi improved 在套件 vim-x11 裡 優點: 速度快 簡單 可靠 缺點: 難學:按鍵太繁雜 VI MODE VIM 的模式共有六種(但通常只有用三種) 命令模式(Command mode): 預設值,您一進入 vim 就是處於這常態模式,只能下按鍵指令,不能輸入編輯文字。 通常可以用來移動游標、剪貼文字及改變模式。 插入模式(Insert mode): 按 「i」 就會進入插入模式,此時才可以鍵入文字,寫您的文章,按 Esc 又會回到正常模式。 通常用來修改文字。 Ex模式(Ex mode): 按冒號「:」就會進入命令列模式,左下角會有一個冒號:出現可下指令。按 Esc 回命令列模式。通常用來儲存及離開。 隨時使用 Esc 可離開目前模式回到命令模式(預設值) 最多連續兩個 EscEsc 總是可以回到命令模式(預設值) 基本操作 進入和離開 vim [lcc09@localhost ~]$ vi :q! # 不儲存離開,如果在其他模式請按ESC切到命令模式。 開檔案 vim filename 檔案如果存在則打開 如果不存在則建立一個新的 [lcc09@localhost ~]$ vi hello.sh 插入模式(Insert mode) 「i」插入模式,從游標後面開始插入文字 除了i外還有AIoO也可以進入。 「A」append to end of line 「I」insert a beginning of line 「o」insert new a line(below) 「O」insert new line(above) Ex模式(Ex mode) 輸入提示符號「:」即可進入Ex模式(Ex mod...

Linux 的文字處理與正規表示式(sed , RE)

文字處理 觀看文字檔案內容 cat 列出文字檔內容 cat file | grep "string" | more 常與grep合用 less 觀看文字檔內容,但可上下跳頁及搜尋。 可觀看 .gz and .bz2的檔案 /text 搜尋 text 內容 n/N 跳到 下一個或上一個搜尋到的 v 打開一個檔案 head 從檔案開頭觀看指定行數內容,如不指定預設為10行 -n 可以決定要看幾行 tail tail -f 觀看目前即時的檔案內容 -n 可以決定要看幾行 linux:~ # cd ~ linux:~ # touch aaa linux:~ # ls aaa -la -rw-r--r--  1 root root 0 2006-09-03 13:07 aaa linux:~ # touch aaa linux:~ # ls aaa -la -rw-r--r--  1 root root 0 2006-09-03 13:09 aaa mtchang@web:~$ cd /var/log mtchang@web:/var/log$ su Password: web:/var/log# tail /var/log/messages -n 10 May 22 12:33:57 web -- MARK -- May 22 12:53:57 web -- MARK -- May 22 13:13:57 web -- MARK -- May 22 13:33:57 web -- MARK -- May 22 13:53:57 web -- MARK -- May 22 14:13:57 web -- MARK -- May 22 14:33:57 web -- MARK -- May 22 14:53:57 web -- MARK -- May 22 15:13:57 web -- MARK -- May 22 15:33:57 web -- MARK -- 搜尋檔案內容 使用grep命令 mtchang@web:~$  grep [-acinv] '搜尋字串' filename 選項說明: -a :將 binary 檔案以...