1 / 12

系統登入與 Shell 的操作機制

系統登入與 Shell 的操作機制. 李爵樺. Kenduest@mail.cynix.com.tw. Shell 基本面. shell 程式用途 shell 程式種類 bash、tcsh、csh 標準的 IO 導向與管線 <、>、| shell 特殊字元 *、?、[、]、- $、#、~、 “string” 、 ‘string’、`string` shell 變數 SHELL、HOME、PATH、PWD、MAILCHECK HISSIZE、HISFILESIZE、HISFILE PS1、IFS、EDITO. 相關操作.

enya
Download Presentation

系統登入與 Shell 的操作機制

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 系統登入與Shell 的操作機制 李爵樺 Kenduest@mail.cynix.com.tw

  2. Shell基本面 • shell 程式用途 • shell 程式種類 • bash、tcsh、csh • 標準的 IO 導向與管線 • <、>、| • shell 特殊字元 • *、?、[、]、- • $、#、~、 • “string” 、 ‘string’、`string` • shell 變數 • SHELL、HOME、PATH、PWD、MAILCHECK • HISSIZE、HISFILESIZE、HISFILE • PS1、IFS、EDITO

  3. 相關操作 • chsh – 變更使用者 shell /etc/shells 檔案內要有紀錄 • export 使用範例: export PATH=$PATH:/usr/local/bin • PS1 變數 – 提示命令訊息使用範例: export PS1=“Linux: \w>” • alias – 設定指令操作的別名使用範例: alias hello=‘ls –l’ • chfn – 變更使用者的個人資訊

  4. SHELL 設定檔案 • bash 設定檔案 • /etc/profile • /etc/bashrc • ~./.bash_profile • ~/.bash_login • ~/.profile • bash 設定檔案讀取流程: • 啟動時: /etc/profile  ~/.bash_profile  ~/.bash_login  ~/.profile • 結束: ~/.bash_logout

  5. 導向功能 • Shell 的重新導向: 1. > 檔案名稱或者是裝置 : ls > list.txt 把執行 ls 結果儲存到 list.txt 檔案 若是原檔案已經存在,或被覆寫 2. >>檔案名稱或者是裝置 : ls >>dirlist.txt 把執行 ls 結果附加到 list.txt 檔案 3. < 檔案名稱或者是裝置 : cat < /etc/fstab • 錯誤的重新導向: 標準輸出檔案代碼為 1 。錯誤輸出檔案代碼為 2 usage: strace > output.txt 2>&1

  6. 導向功能 • 管線功能: • usage : 程式1 | 程式 2 | 程式 3 ..... • 範例 : ☆ ls –l / | grep “usr” ☆ man adduser | col –b > adduser.txt ☆ cat /etc/fstab | sort

  7. 萬用字元 • 萬用字元: * 等於任意長度的字元、字串 ? 等於單一任意字元 [] 等於括號內的某一字元 {} 等於引號內某一字串 - 等於某字元類別中的某個範圍 • 範例: 1.ls* 2.s? 3.boo[t] 4. quot[a-z] 5. rc.{local,sysinit}

  8. 萬用字元 • 萬用字元: (續上面) • * 任意長度字串,可以為空的字串 比方 xyz、testxyz 都符合 *xyz ? : 等於單一任意字元,空字元欄位不符合 • ? 任意單一字元 比方 xyz 符合 x?z 。不過 xz 不符合 x?z • [] 等於括號內的某一字元 • - 等於某字元類別中的某個範圍 比方 abc、abz、aby 符合 ab[a-z] • {}等於引號內某一字串 比方 rc.local 與 rc.sysinit 可以使用 rc.{local,sysinit} 表示

  9. 特殊字元 • ; 單一命令結束 usage: free;df • $ 取出某個變數 usage: echo $HOME • ‘字串’ 字串引數,變數不展開 usage: echo “this is a test message” echo ‘$HOME’ • “字串” 字串引數,可插入變數 usage: echo “$HOME” • ‘字串’ 執行該字串命令 echo “Current Directory: `pwd`”

  10. 行程運作 • & : 讓某個程式背景執行: usage : top & • jobs : 列出使用 & 背景執行的程式 usage : jobs [1]- Stopped (signal) pine [2]+ Stopped (tty output) top • ctrl z 熱鍵 : 可以讓某個程式暫時執行 • bg : 該指令配合 ctrl z 熱鍵運作,把某程式丟到背景 • fg : 返為原使用背景執行的程式。 usage: fg %1 返為 job id 為 1 的程式 usage: fg 直接返回上一個 job

  11. 系統管理 • dmesg – 顯示開機過程資訊 • df - 顯示各分割區空間資訊 • du – 顯示目錄所使用的空間 • free – 顯示目前記憶體配置狀態 • top - 顯示目前記憶體配置狀態 • ps – 顯示行程狀態 • a – 包含其他使用者 (tty) u – 詳細顯示程序的詳細資料 • x – 包含背景、無 tty 的程式 • STAT : S(Sleeping),R(Runable),T(Stopped),Z(Zombile) D(Uninterruptable Sleep),W(Swapout) • kill – 刪除某各行程 # kill process_pid -1 : SIGHUP -9 : SIGKILL -15 : SIGTERM

  12. 系統管理 • 變更程式執行優先權: • 等級分類 40 級,-20 ~ 19 • 預設等級 0 • -20 最高,19 最低 • 一般使用者可以設定執行等級為 0 ~ 19 • nice –15 program  設定執行 program 優先等級為16 • nice - -10 program  設定執行 program 優先等級為 -10

More Related