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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:48:11  来源:igfitidea点击:

What does "/dev/null" mean at the end of shell commands

linuxshell

提问by Sepehr Samini

What is the difference between the following commands?

以下命令有什么区别?

ssh myhostname "command1; command2;...commandn;" 2>/dev/null
ssh myhostname "command1; command2;...commandn;" 
  1. what does 2>mean?

  2. what does /dev/nullmean? I read somewhere that result of command will be write to file /dev/nullinstead of console! Is it right? It seems strange for me that the name of file be null!

  1. 是什么2>意思?

  2. 是什么/dev/null意思?我在某处读到命令的结果将写入文件/dev/null而不是控制台!这样对吗?对我来说,文件的名称是null!

采纳答案by Malvolio

2>means "redirect standard-error" to the given file.

2>意味着“重定向标准错误”到给定的文件。

/dev/nullis 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 2you 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。