$pwd >> home/cc/drama/hospital
cp drama/fire.txt hospital/ >> Error
無法Tab 出 parrent directory,譬如說:
cc/ drama music tea 三個資料夾
當你要改變工作路徑到 tea/, 你輸入 cd ../mus 按 Tab,不會出現 自動出現music
萬用字元(Wildcard)
* is a wildCard
cp * safe/ 複製所有檔案,但不包含 directory,明明 cp(copy) 可以複製 file 和 directory。
clear 清理 bash 畫面
cls 清理 window command prompt
rm(remove)
可刪除 file 及 directory,但碰上directory要加上 option -r 才可刪除之。
__________________________________________
Command Line (二)
水管(pipe) 左手邊 stdout ( stand out )
右手邊 stdin (stand in )
解讀順序 從左至右,i.e. stdout => stdin
< : 右手邊作為 stdin ,stdout去左手邊程式。
>> ( append 附加 )
> ( overwrite 複寫 )
uniq : 消除相鄰重複,
範例 : sort deserts.txt | uniq > uniq-deserts.txt,
從左至右,先將 deserts.txt 裡的條目先排序,後由 pipe | 導入 uniq ,消除相鄰重複,後導入 uniq-deserts.txt ,若碰上 工作目錄沒有 uniq-deseerts.txt 就先建立uniq-deserts.txt 後導入內容。
grep ( global regular expression print ), 範例: grep Moun mountains.txt,
從 mountains.txt 裏頭,搜尋每一行有 Mount 開頭的單字,並印在螢幕上,i.e. 輸出結果的每一行都有 Mount 起首的字。
範例 : grep -i Moun mountains.txt > chung-hao.txt,不分大小寫搜尋有 moun 起首的單字結果,並導入 chung-hao.txt裏頭。
grep -R Arctic /home/ccuser/workspace/geography -R(recursive_遞迴,每個檔案不放過的搜尋)
搜尋 geography,所有包含 "Arctic" 的檔案名稱及其包含該字串的那一行。
grep -R Arctic 搜尋當前路徑的所有檔案
grep -Rl Arctic 只列出符合結果的檔案名稱
sed ( stream editor),
舉例: sed 's/snow/rain/' forests.txt ,'s/(substitution)/snow(目標字串)/rain(替代字串)/',
把forests.txt裏頭的snow取代成 rain,但是如果遇到 某一行有兩個snow時只會替換到從左邊數來第一個遇到的 snow而已,可以透過 's/snow/rain/g(global)' 替換掉所有的snow。
注意: 's/snow/rain/'要加斜線/,不然ERROR。
沒有留言:
張貼留言