dev null 2 1 什麼意思

2022-03-20 08:43:40 字數 681 閱讀 4273

在unix中,標準輸入裝置 stdin是0, stdout 是1, stderr是 2。

/dev/null 2>&1這樣的寫法意思是將標準輸出和錯誤輸出全部重定向到/dev/null中,也就是將產生的所有資訊丟棄.

下面說說command > file 2>filecommand > file 2>&1有什麼不同的地方.

首先~command > file 2>file的意思是將命令所產生的標準輸出資訊,和錯誤的輸出資訊送到file 中.command  > file 2>file這樣的寫法,stdout和stderr都直接送到file中, file會被開啟兩次,這樣stdout和stderr會互相覆蓋,這樣寫相當使用了fd1和fd2兩個同時去搶占file 的管道.

command >file 2>&1這條命令就將stdout直接送向file, stderr 繼承了fd1管道後,再被送往file,此時,file 只被開啟了一次,也只使用了乙個管道fd1,它包括了stdout和stderr的內容.

從io效率上,前一條命令的效率要比後面一條的命令效率要低,所以在編寫shell指令碼的時候,較多的時候我們會用command > file 2>&1這樣的寫法.

dev null 2 1 是什麼意思

在linux中 0 表示鍵盤輸入 stdin 1 表示標準輸出 stdout 系統預設是1 2 表示錯誤輸出 stderr shell命令 command dev null 2 1 等同於 command 1 dev null 2 1 1 command 表示shell命令或乙個可執行的程式 2 表...

相關 dev null 2 1 詳解

用 dev null 2 1 這樣的寫法.這條命令的意思是將標準輸出和錯誤輸出全部重定向到 dev null中,也就是將產生的所有資訊丟棄.下面就為大家來說一下,command file 2 file與command file 2 1有什麼不同的地方.首先command file 2 file的意思...

相關 dev null 2 1 詳解

用 dev null 2 1 這樣的寫法.這條命令的意思是將標準輸出和錯誤輸出全部重定向到 dev null中,也就是將產生的所有資訊丟棄.下面就為大家來說一下,command file 2 file與command file 2 1有什麼不同的地方.首先command file 2 file的意思...