2015年8月20日 星期四

RH124_04_Creating, viewing, and editing text files

1.輸出文件


>file          標準輸出,覆蓋文件
>>file           標準輸出,文件續寫
2>file           錯誤輸出,覆蓋文件
2>/dev/null           錯誤輸出到/dev/null
&>file           標準輸出和錯誤輸出,覆蓋文件
>>file >2&1           標準輸出和錯誤輸出,文件續寫


2.Constructing pipelines 
第一個指令的輸出,接續當下個指令的輸入,最後結果輸出到一個檔案
$ls -l /usr/bin | less
$ls | wc -l > /tmp/how-many-files
$ls -t | head -n 10 > /tmp/ten-last-changes-files

每個指令執行完畢皆輸出
$ls -l | tee /temp-save-output

3.編輯檔案內容
$vim filename
i     to enter insert mode
Esc     to return to command mode
x     to delete a selection of text 
u     to undo mistaken edits on the current line
y     to yank (copy) the selection
p     to put (paste) the selection
w     to write (save) the file and remain in command mode for more editing
:wq     to write the file and quit Vim
:q!     to quit Vim, but discard all file changes since the last write

沒有留言: