Chapter 4. Creating, Viewing, and Editing Text Files.
- Standard input, standard output, and standard error
- Redirecting output to a file
# command > /tmp/file1
將 command 執行後,所回傳的正確的訊息以覆蓋的方法輸出到 file1
# command >> /tmp/file1
將 command 執行後,所回傳的正確的訊息以累加的方法輸出到 file1
如果 file1 不存在,則會新增 file1 再輸出
# command 2> /tmp/file1
將 command 執行後,所回傳的錯誤訊息以覆蓋的方法輸出到 file1
# command 2>> /tmp/file1
將 command 執行後,所回傳的錯誤訊息以累加的方法輸出到 file1
如果 file1 不存在,則會新增 file1 再輸出
# command 2> /dev/null
忽視 command 執行後,所回傳的錯誤訊息
# command &> /tmp/file1
將 command 輸出的正確與錯誤訊息一同輸出到 file1
# command >> /tmp/file1 2>&1
將 command 輸出的正確與錯誤訊息一同輸出到 file1
如果 file1 不存在,則會新增 file1 再輸出
- Constructing pipelines
※ less, more, head, tail, tee, wc, mail
都是可以接受 standard input 的管線命令
# ls -l /usr/bin | less
# ls | wc -l > /tmp/how-many-files
# ls -t | head -n 10 > /tmp/ten-last-changed-files
# ls -l | tee /tmp/saved-output
# ls -l | tee /dev/pts/0 mail -s subject
tee 會同時將資料流分送到檔案與螢幕
- Editing files with Vim
‧ Press i to enter insert mode
‧ Press Esc to return to command mode
‧ Press u to undo mistaken edits on the current line
‧ Press x to delete a selection of text
‧ Press y to yank(copy) the selection
‧ Press p to put(paste) the selection
‧ Enter :w to write(save) the file and remain in command mode
for more editing
‧ Enter :wq to write the file and quit Vim
‧ Enter :q! to quit Vim, but discard all file changes since the last write
- Editing files with gedit
圖形化介面操作,如Windows下的記事本