我运行这个命令
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
.....
我尝试过 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
.....
如何避免有关 cgroup2 挂载的烦人消息?发行版是 Slackware 15.0
答案1
您的重定向位于管道中的错误点。据推测,错误来自ss
命令,因此您应该隐藏错误输出。或者,您可以将命令的输出和重定向作为一个整体进行分组。
以下是一些抑制错误的可能解决方案:
重定向生成消息的命令的标准错误:
ss -tulpnoea 2> /dev/null|grep -i water|grep -v 127
在子 shell 中运行命令并重定向子 shell 的标准错误:
(ss -tulpnoea|grep -i water|grep -v 127) 2> /dev/null
对命令进行分组并重定向该组的标准错误:
{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> /dev/null
或者,如果您特别想抑制该错误而不是其他错误(取决于 shell 支持)
ss -tulpnoea 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)|grep -i water|grep -v 127)
(ss -tulpnoea|grep -i water|grep -v 127) 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)
{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)