如何删除这条恼人的消息:“无法找到 cgroup2 安装”?

elb*_*rna 4 io-redirection stderr ss

我运行这个命令

ss -tulpnoea|grep -i water|grep -v 127
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
.....
Run Code Online (Sandbox Code Playgroud)

我尝试过 2> /dev/null...

 ss -tulpnoea|grep -i water|grep -v 127 2> /dev/null
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    .....
Run Code Online (Sandbox Code Playgroud)

如何避免有关 cgroup2 挂载的烦人消息?发行版是 Slackware 15.0

bxm*_*bxm 13

您的重定向位于管道中的错误点。据推测,错误来自ss命令,因此您应该隐藏错误输出。或者,您可以将命令的输出和重定向作为一个整体进行分组。

以下是一些抑制错误的可能解决方案:

重定向生成消息的命令的标准错误:

ss -tulpnoea 2> /dev/null|grep -i water|grep -v 127 
Run Code Online (Sandbox Code Playgroud)

在子 shell 中运行命令并重定向子 shell 的标准错误:

(ss -tulpnoea|grep -i water|grep -v 127) 2> /dev/null
Run Code Online (Sandbox Code Playgroud)

对命令进行分组并重定向该组的标准错误:

{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> /dev/null
Run Code Online (Sandbox Code Playgroud)

或者,如果您特别想抑制该错误而不是其他错误(取决于 shell 支持)

ss -tulpnoea 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)|grep -i water|grep -v 127) 
Run Code Online (Sandbox Code Playgroud)
(ss -tulpnoea|grep -i water|grep -v 127) 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)
Run Code Online (Sandbox Code Playgroud)
{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)
Run Code Online (Sandbox Code Playgroud)