Linux shell 命令末尾的“/dev/null”是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13408619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "/dev/null" mean at the end of shell commands
提问by Sepehr Samini
What is the difference between the following commands?
以下命令有什么区别?
ssh myhostname "command1; command2;...commandn;" 2>/dev/null
ssh myhostname "command1; command2;...commandn;"
what does
2>
mean?what does
/dev/null
mean? I read somewhere that result of command will be write to file/dev/null
instead of console! Is it right? It seems strange for me that the name of file benull
!
是什么
2>
意思?是什么
/dev/null
意思?我在某处读到命令的结果将写入文件/dev/null
而不是控制台!这样对吗?对我来说,文件的名称是null
!
采纳答案by Malvolio
2>
means "redirect standard-error" to the given file.
2>
意味着“重定向标准错误”到给定的文件。
/dev/null
is the null file. Anything written to it is discarded.
/dev/null
是空文件。任何写入它的东西都会被丢弃。
Together they mean "throw away any error messages".
它们一起的意思是“丢弃任何错误消息”。
回答by Madbreaks
'/dev/null' essentially means "into the void", discarded. The 2
you mention refers to error output, where it should be directed.
'/dev/null' 本质上的意思是“进入虚无”,被丢弃了。在2
你提到的是指错误输出,它应该被引导。
回答by Ed Heal
2> means sending standard error to something
2> 表示向某物发送标准错误
/dev/null means a bin
/dev/null 表示一个 bin
回答by BrenanK
1) Pipe everything on standard error to /dev/null (so ignore it and don't display it)
1) 将标准错误上的所有内容通过管道传送到 /dev/null (因此忽略它并且不显示它)
2) Dev null just points to nowhere, pipe anything to that, and it disappears.
2) Dev null 只是指向无处,通过管道将任何东西传递给它,然后它就消失了。
回答by Jimmy
1 is stdout. 2 is stderr.
1 是标准输出。2 是标准错误。
Then sometimes you find 2>&1
, that means redirecting stderr to stdout.
然后有时您会发现2>&1
,这意味着将 stderr 重定向到 stdout。