如何将后台应用程序的输出重定向到/ dev/null

Kir*_*ran 89 linux ubuntu

我想将Linux中后台应用程序生成的输出重定向到/ dev/null.

我正在使用kate文本编辑器,它打印终端上的所有调试消息,我想重定向到/ dev/null.

知道怎么做吗?

谢谢

evi*_*ead 210

你用:

yourcommand  > /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)

如果它应该在后台运行添加一个 &

yourcommand > /dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)

>/dev/null 2>&1意味着重定向stdout/dev/nullAND stderrstdout那个时间点的地方

如果你想stderr在控制台上出现,只有stdout/dev/null可以使用:

yourcommand 2>&1 > /dev/null
Run Code Online (Sandbox Code Playgroud)

在这种情况下stderr,重定向到stdout(例如您的控制台),然后将原始文件stdout重定向到/dev/null

如果程序不应该终止,您可以使用:

nohup yourcommand &
Run Code Online (Sandbox Code Playgroud)

没有任何参数,所有输出都在nohup.out中


Jim*_*ker 7

这些也将重定向:

yourcommand  &> /dev/null

yourcommand  >& /dev/null
Run Code Online (Sandbox Code Playgroud)

尽管 bash 手册说第一个是首选。