Linux中的輸入輸出重定向
阿新 • • 發佈:2018-12-14
符號 | 解釋 |
---|---|
> file | //標準輸出重定向到檔案—覆蓋 |
>>file | //標準輸出重定向到檔案—追加 |
2>file | //標準錯誤重定向到檔案—覆蓋 |
2>>file | //標準錯誤重定向到檔案—追加 |
2>/dev/null | //標準錯誤重定向到回收站 |
&>file | //標準輸出和標準錯誤重定向到檔案—覆蓋 |
>>file 2>&1 | //標準輸出和標準錯誤重定向到檔案—追加 |
配置舉例
標準輸出
date命令用於輸出當前時間
[[email protected] ~]# date
Sat Dec 8 10:08:37 CST 2018
把date輸出覆蓋到abc中
[[email protected] tmp]# date > abc
把date輸出追加到abc中
[[email protected] tmp]# date >> abc
把/etc/passwd檔案中的內容輸出到abc檔案中
[ [email protected] tmp]# cat /etc/passwd > abc
標準錯誤輸出
[[email protected] tmp]# 1234 2> abc
[[email protected] tmp]# 1234 2> /dev/null
標準輸出和標準錯誤重定向到檔案—追加
[email protected] tmp]# 1234 >> abc 2>&1
實際工作舉例:
1、可以把一個程式的錯誤資訊輸出到某一個檔案,可以用於指令碼,也可以用於普通使用
2、可以快速清空一個大檔案中的內容