当我从与窗口系统相关的终端(例如 gnome 或 kde)启动应用程序时,这些应用程序通常会在我的终端中发送各种垃圾消息。如何让这些应用程序关闭?
例如,如果我输入:
okular somepdf.pdf &
Run Code Online (Sandbox Code Playgroud)
弹出一个显示 pdf 文件的窗口,我可以在终端旁边阅读 pdf,完成后我关闭。
下面是一个典型的例子:
:~$ cd Documents
:~/Documents$ okular equi.dvi &
[1] 5823
Run Code Online (Sandbox Code Playgroud)
当我关闭时,它会将这些垃圾发送到终端:
:~/Documents$ okular(5823)/kdeui (kdelibs) KXMLGUIClient::~KXMLGUIClient: 0x2322528 deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.
d
d: command not found
[1]+ Done okular equi.dvi
[1]+ Done okular equi.dvi
:~/Documents$
Run Code Online (Sandbox Code Playgroud)
我唯一想看到的是:
:~$ cd Documents
:~/Documents$ okular equi.dvi &
:~/Documents$
Run Code Online (Sandbox Code Playgroud)
也许那条消息是一些错误,我不在乎,也不想知道。
是否可以抑制这些消息?
有些人将此问题标记为“如何抑制输出”问题的重复,但这只是我想要的部分内容:
我想自动抑制某些应用程序的所有输出。例如 okular 是一个图形应用程序,所以我永远不会关心它在我的终端中说什么。
所以就像我上面说的,我希望行为是:
:~$ cd Documents
:~/Documents$ okular equi.dvi &
:~/Documents$
Run Code Online (Sandbox Code Playgroud)
而不是像
:~$ cd Documents
:~/Documents$ okular equi.dvi > whatever &
:~/Documents$
Run Code Online (Sandbox Code Playgroud)
小智 8
要抑制 STDOUT:
yourcommand 1>/dev/null
Run Code Online (Sandbox Code Playgroud)
抑制 STDERR
yourcommand 2>/dev/null
Run Code Online (Sandbox Code Playgroud)
从 bash 4 开始,您可以同时抑制:
yourcommand &>/dev/null
Run Code Online (Sandbox Code Playgroud)
您还可以使用kdedebugdialog工具禁用 KDE 的调试信息并禁用所选模块的输出(或所有调试输出)。