linux /dev/null 21,/dev/null 21 21 与 的意思
在linux中,0,1,2,/dev/null,>,>>的意思:
標(biāo)準(zhǔn)輸入stdin的文件描述符為0
標(biāo)準(zhǔn)輸出stdout的文件描述符為1
標(biāo)準(zhǔn)錯(cuò)誤stderr的文件描述符為2
/dev/null為空設(shè)備,相當(dāng)于垃圾桶
輸出重定向符號(hào)為>
>為覆蓋
>>為追加
2>1與2>&1的區(qū)別
2>1把標(biāo)準(zhǔn)錯(cuò)誤stderr重定向到文件1中
2>&1把標(biāo)準(zhǔn)錯(cuò)誤stderr重定向到標(biāo)準(zhǔn)輸出stdout
示例:
test.sh
#! /bin/sh
t
date
標(biāo)準(zhǔn)輸出重定向到log,標(biāo)準(zhǔn)錯(cuò)誤輸出到終端上
$ 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文件)標(biāo)準(zhǔn)輸出重定向到log,標(biāo)準(zhǔn)錯(cuò)誤重定向到文件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文件)標(biāo)準(zhǔn)輸出重定向到log,標(biāo)準(zhǔn)錯(cuò)誤重定向到標(biāo)準(zhǔn)輸出
$ 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文件)標(biāo)準(zhǔn)輸出重定向到空設(shè)備
$ ls
log test.sh
$ rm log
$ ls
test.sh
$ ./test.sh >/dev/null
./test.sh: 3: ./test.sh: t: not found
$ ls
test.sh
標(biāo)準(zhǔn)錯(cuò)誤重定向到空設(shè)備
$ ls
test.sh
$ ./test.sh 2>/dev/null
2017年 06月 29日 星期四 14:23:41 CST
$ ls
test.sh
標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤全定向到空設(shè)備
$ ls
test.sh
$ ./test.sh >/dev/null 2>&1
$ ls
test.sh
總結(jié)
以上是生活随笔為你收集整理的linux /dev/null 21,/dev/null 21 21 与 的意思的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国二c语言改错题答案,c语言国二考试编程
- 下一篇: 【Linux入门连载一】[Win10下安