Linux 如何将后台应用程序的输出重定向到 /dev/null
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8220098/
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
How to redirect the output of an application in background to /dev/null
提问by Kiran
I would like to redirect the output generated from a background application in Linux to /dev/null.
我想将从 Linux 中的后台应用程序生成的输出重定向到 /dev/null。
I am using kate text editor and it prints all the debug messages on the terminal which I would like to redirect to /dev/null.
我正在使用 kate 文本编辑器,它在终端上打印所有我想重定向到 /dev/null 的调试消息。
Any idea how to do it ?
知道怎么做吗?
Thanks
谢谢
采纳答案by evildead
You use:
你用:
yourcommand > /dev/null 2>&1
If it should run in the Background add an &
如果它应该在后台运行,请添加一个 &
yourcommand > /dev/null 2>&1 &
>/dev/null 2>&1
means redirect stdout
to /dev/null
AND stderr
to the place where stdout
points at that time
>/dev/null 2>&1
表示重定向stdout
到/dev/null
ANDstderr
到当时stdout
点的地方
If you want stderr
to occur on console and only stdout
going to /dev/null
you can use:
如果你想stderr
在控制台上发生并且只stdout
去/dev/null
你可以使用:
yourcommand 2>&1 > /dev/null
In this case stderr
is redirected to stdout
(e.g. your console) and afterwardsthe original stdout
is redirected to /dev/null
在这种情况下stderr
被重定向到stdout
(例如您的控制台),然后原始stdout
被重定向到/dev/null
If the program should not terminate you can use:
如果程序不应终止,您可以使用:
nohup yourcommand &
Without any parameter all output lands in nohup.out
没有任何参数,所有输出都在 nohup.out
回答by Jim Hunziker
These will also redirect both:
这些也将重定向:
yourcommand &> /dev/null
yourcommand >& /dev/null
though the bash manual says the first is preferred.
尽管 bash 手册说第一个是首选。