如何防止“iptools ss”在标准输出上软包装长行?

Tho*_*ner 4 linux terminal

我已经习惯了netstat -taulpen,虽然我不知道所有标志的具体作用,但它提供了一个很好的可读网络程序表,并且当以 sudo 运行时可以显示所有进程名称与地址和套接字内联他们听等等。

随着ss我接近:

$ ss -tlnp

  -n, --numeric    don't resolve service names
  -l, --listening  display listening sockets
  -p, --processes  show process using socket
  -t, --tcp        display only TCP sockets
Run Code Online (Sandbox Code Playgroud)

正如您可以想象的那样,这给出了这样的输出:我已经手动包装了出现在终端输出中的行:

State      Recv-Q Send-Q                                  Local Address:Port                                    Peer Address:Port 
LISTEN     0      50                                                  *:139                                                *:*      
users:(("smbd",874,33))
LISTEN     0      5                                           127.0.1.1:53                                                 *:*      
users:(("dnsmasq",1528,5))
LISTEN     0      128                                         127.0.0.1:631                                                *:*      
users:(("cupsd",782,11))
Run Code Online (Sandbox Code Playgroud)

所以我的问题是我的终端模拟器中有很多空间,但是 ss 非常坚定地将前几列包装到 100% 宽度,而剩余的列会脱落并换行,即使 xxd 中没有显示文字换行符.

Tho*_*ner 5

1) 通过一个去除 tty 宽度上下文的程序进行管道传输,例如 cat

$ ss -tlnp | less
$ ss -tlnp | cat
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      50                        *:139                      *:*      users:(("smbd",874,33))
LISTEN     0      5                 127.0.1.1:53                       *:*      users:(("dnsmasq",1528,5))
LISTEN     0      128               127.0.0.1:631                      *:*      users:(("cupsd",782,11))
Run Code Online (Sandbox Code Playgroud)

2)谎报你的tty宽度stty

我不认为这是一个解决方案,因为它涉及手动修改环境以在程序上下文中实现效果。

但这确实有效,以为我永远不会费心使用它:

# Tell the environment this terminal is only 80 chars wide
# (or however slim you need to view the overflow)
$ stty cols 80

$ ss -tlnp
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      50                        *:139                      *:*      users:(("smbd",874,33))
LISTEN     0      5                 127.0.1.1:53                       *:*      users:(("dnsmasq",1528,5))
LISTEN     0      128               127.0.0.1:631                      *:*      users:(("cupsd",782,11))
Run Code Online (Sandbox Code Playgroud)