如何将所有输出重定向到/dev/null? [英] How can I redirect all output to /dev/null?

查看:320
本文介绍了如何将所有输出重定向到/dev/null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后台运行程序(google-chrome),但是阻止它向终端输出任何消息.

I want to run a program (google-chrome) in the background, but prevent it from outputting any messages to the terminal.

我尝试这样做:

google-chrome 2>&1 1>/dev/null &

但是,终端仍然填满,没有类似以下消息:

However, the terminal still fills up without messages like:

[5746:5746:0802/100534:ERROR:object_proxy.cc(532)]无法调用方法:org.chromium.Mtpd.EnumerateStorag ...

[5746:5746:0802/100534:ERROR:object_proxy.cc(532)] Failed to call method: org.chromium.Mtpd.EnumerateStorag...

我做错了什么?如何将输出的全部重定向到/dev/null?

What am I doing wrong? How do I redirect all the output to /dev/null?

推荐答案

重定向运算符从左到右进行评估.您错误地将2>&1放在第一个位置,该位置将2指向同一位置,因为当前尚未指向1,因此当前指向的1是本地终端屏幕.您需要执行以下任一操作:

Redirection operators are evaluated left-to-right. You wrongly put 2>&1 first, which points 2 to the same place, as 1 currently is pointed to which is the local terminal screen, because you have not redirected 1 yet. You need to do either of the following:

2>/dev/null 1>/dev/null google-chrome &

2>/dev/null 1>&2 google-chrome &

重定向操作符相对于命令的位置无关紧要.您可以将它们放在命令之前或之后.

The placement of the redirect operators in relation to the command does not matter. You can put them before or after the command.

这篇关于如何将所有输出重定向到/dev/null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆