1 / 5

Redirection 概念說明

Redirection 概念說明. input redirection: 將資料 “ 再 ” 輸入到某一命令去做處理 ( 用 < 符號 ) output redirection: 將資料 “ 再 ” 輸出到某一命令去做處理  ( 用 > 符號 ) stdin: 標準輸入設備 , 如鍵盤 , 滑鼠 , … stdout: 標準輸出設備 , 如螢幕 stderr: 可呈現標準錯誤的設備 , 如螢幕 filter: 如資料從 stdin 讀入 , 而結果送到 stdout 就 稱這個指令具有 filter 的功能

jason
Télécharger la présentation

Redirection 概念說明

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. Redirection 概念說明 • input redirection: 將資料“再”輸入到某一命令去做處理 (用<符號) • output redirection: 將資料“再”輸出到某一命令去做處理 (用>符號) • stdin: 標準輸入設備,如鍵盤,滑鼠,… • stdout: 標準輸出設備,如螢幕 • stderr: 可呈現標準錯誤的設備,如螢幕 • filter:如資料從stdin讀入,而結果送到stdout就 • 稱這個指令具有filter的功能 • pager: 分頁器,如 less, more,pager不是filter • pipe: 讓前一個指令流到後面的指令去 (|)

  2. I/O Redirection • 輸出導向 > • 例:ls –l > fname (再用 cat fname 看內容) • cat fname > fname1 • cat > fname2 (代表由user自行打字輸入,直到按^C結束) • man ls > fname3 • 輸入導向 < •  例:cat < fname2 (將fname2輸入由cat列出內容,而非由stdin) • patch < patch-2.2.13 (修補程式只能用<) • 附加輸入 •  例:cat << end (讓user自行打入內容,直到打了”end”才結束) • mail lhli@cyut.edu.tw << q • cat << q > 檔名 • 輸出錯誤導向 &> •  例:ls –l dir &> fname4(不論正確與否訊息都送到fname4去)

  3. Pipe • Pipe是用符號|來表示,它可將指令所執行的輸出結果送到另一個指令去執行 • 例: • cat fname1 fname2 > fname3 • (將fname1與fname2合併到fname3) • cat fname1 fname2 fname5 fname6 > fname7 • (將上面四個檔合併到fname7去) • ls –l | more • man ls | less • who | grep s92140 | sort | less • who | grep s92140 | sort > fname3 • cat fname2 | less

  4. grep • grep是GNU程式裡最常被用的指令,它可以協助快速的搜尋字串 • 例:grep FILE fname.txt(找所有檔案中有FILE的內容) • grep dog * (找所有檔案中有dog 字元的內容) • grep –e “Hello” fname.txt(找出在檔案中含 • hello的內容) • grep –c “Hello” fname.txt (算出 “Hello”在檔 • 案中的次數) • 組合練習: • who | grep –c “s9314” |less (可列出目前上線 • 大一的學生數)

  5. 指令的組合基礎與練習 • 指令 | 指令 (例: finger | less) • 指令 > 檔案 (例: cat filename1 > filename2) • 指令 參數 < 檔案 (例: mail lily@cyut.edu.tw < fname) • Q1: 請找出目前上機人數中是資管系四技大二的學生, 並將它列出 • Q2: 請將目前目錄下所有檔名中有 “dir”三個字母的檔案全部輸出到另一個檔案 OUTFILE.txt去

More Related