linux /dev/null 21,/dev/null 21 21 与 的意思
在linux中,0,1,2,/dev/null,>,>>的意思:
標準輸入stdin的文件描述符為0
標準輸出stdout的文件描述符為1
標準錯誤stderr的文件描述符為2
/dev/null為空設備,相當于垃圾桶
輸出重定向符號為>
>為覆蓋
>>為追加
2>1與2>&1的區別
2>1把標準錯誤stderr重定向到文件1中
2>&1把標準錯誤stderr重定向到標準輸出stdout
示例:
test.sh
#! /bin/sh
t
date
標準輸出重定向到log,標準錯誤輸出到終端上
$ ls
test.sh
$ ./test.sh > log
./test.sh: 3: ./test.sh: t: not found
$ ls
log test.sh
$ cat log
2017年 06月 28日 星期三 09:30:39 CST
(刪除log文件)標準輸出重定向到log,標準錯誤重定向到文件1
$ ls
log test.sh
$ rm log
$ ls
test.sh
$ ./test.sh > log 2>1
$ ls
1 log test.sh
$ cat log
2017年 06月 28日 星期三 09:34:32 CST
$ cat 1
./test.sh: 3: ./test.sh: t: not found
(刪除log文件及1文件)標準輸出重定向到log,標準錯誤重定向到標準輸出
$ ls
1 log test.sh
$ rm 1 log
$ ls
test.sh
$ ./test.sh > log 2>&1
$ ls
log test.sh
$ cat log
./test.sh: 3: ./test.sh: t: not found
2017年 06月 28日 星期三 09:36:49 CST
(刪除log文件)標準輸出重定向到空設備
$ ls
log test.sh
$ rm log
$ ls
test.sh
$ ./test.sh >/dev/null
./test.sh: 3: ./test.sh: t: not found
$ ls
test.sh
標準錯誤重定向到空設備
$ ls
test.sh
$ ./test.sh 2>/dev/null
2017年 06月 29日 星期四 14:23:41 CST
$ ls
test.sh
標準輸出和標準錯誤全定向到空設備
$ ls
test.sh
$ ./test.sh >/dev/null 2>&1
$ ls
test.sh
總結
以上是生活随笔為你收集整理的linux /dev/null 21,/dev/null 21 21 与 的意思的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国二c语言改错题答案,c语言国二考试编程
- 下一篇: 微信怎样免费提现