ssコマンドの各結果は2行を占めます。

ssコマンドの各結果は2行を占めます。

私は開いているポートを確認しようとしましたnetstat -anlptu
このコマンドは少し使用されていないので、使い始めましたが、アイテムごとにss -anptu2行が必要です。結果は実用的ではありません。
私はDebianを使用しています。

 

netstat -anlptu:

tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -               
tcp        0      0 192.168.0.106:xxxxx     192.0.x.y:443          ESTABLISHED 5081/firefox    

読みやすく明確です。

 

ss -anptu:

tcp    LISTEN     0      20                                                       127.0.0.1:25                                                                           *:*
 users:(("exim4",pid=823,fd=3))
tcp    LISTEN     0      128                                                              *:22                                                                        *:*                  
 users:(("sshd",pid=807,fd=3))
tcp    ESTAB      0      272                                                  192.168.1.200:22                                                            78.224.x.y:36028              
 users:(("sshd",pid=849,fd=3),("sshd",pid=840,fd=3))
tcp    LISTEN     0      20                                                             ::1:25                                                                          :::*                  
 users:(("exim4",pid=823,fd=4))
tcp    LISTEN     0      128                                                             :::22                                                                       :::*                  
 users:(("sshd",pid=807,fd=4))

明らかに読むのは簡単ではありません。
一部の列が誤ってソートされました。

 

lessまたはにリダイレクトする場合more

tcp    LISTEN     0      20     127.0.0.1:25                    *:*                   users:(("exim4",pid=823,fd=3))
tcp    LISTEN     0      128       *:22                 *:*                   users:(("sshd",pid=807,fd=3))
tcp    ESTAB      0      40     192.168.1.200:22              78.224.x.y:36028               users:(("sshd",pid=849,fd=3),("sshd",pid=840,fd=3))
tcp    LISTEN     0      20      ::1:25                   :::*                   users:(("exim4",pid=823,fd=4))
tcp    LISTEN     0      128      :::22                :::*                   users:(("sshd",pid=807,fd=4))

各項目は行を占めますが、列はソートされません。もう一度読むのは簡単ではありません。

 

-->読みやすい出力を取得する方法はss

ベストアンサー1

使用column。たとえば、

ss -anpt | column -t -x | less

私が得た結果は次のとおりです。

State       Recv-Q  Send-Q  Local                       Address:Port                  Peer                                         Address:Port
LISTEN      0       100     127.0.0.1:143               0.0.0.0:*
LISTEN      0       100     0.0.0.0:465                 0.0.0.0:*
LISTEN      0       128     0.0.0.0:42449               0.0.0.0:*
LISTEN      0       10      0.0.0.0:5298                0.0.0.0:*                     users:(("pidgin",pid=30003,fd=19))

注:私は282列幅(Liberation Mono Regular 11を使用する1440p画面で端末の最大幅)の端末を実行しています。より狭い端子のYMMV。

columncolumnsで行われますautogen。テーブル列にテキスト書式を自動的に割り当てる優れた操作を実行します。

column元のソースがどこから来たかはわかりませんが、Debian システムではbsdmainutilパッケージにあります。他のLinuxディストリビューションでも同様の名前のパッケージに存在する可能性があります。

Package: bsdmainutils
Version: 11.1.2
Description-en: collection of more utilities from FreeBSD
 This package contains lots of small programs many people expect to find when
 they use a BSD-style Unix system.
 .
 It provides banner (as printerbanner), calendar, col, colcrt, colrm, column,
 from (as bsd-from), hexdump (or hd), look, lorder, ncal (or cal), ul, and
 write (as bsd-write).
 .
 This package used to contain whois and vacation, which are now distributed in
 their own packages. Also here was tsort, which is now in the "coreutils"
 package.

/usr/share/doc/bsdmainutils/copyrightパッケージのマニュアルには次のように記載されています。

これは、FSFがまだGNU用に書き換えていない4.4BSD-Liteプログラムの集まりです。 Debian Linuxに含まれるように作られています。ここにあるプログラムは、GNUソースコードで利用できるようになると置き換えられます。

そして

このパッケージは、UCB BSDライセンス条件に従って再配布できます。

著作権(C)1980 -1998カリフォルニア大学リージョン。すべての権利を保有。

おすすめ記事