AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 421838
Accepted
Gregory MOUSSAT
Gregory MOUSSAT
Asked: 2018-02-05 08:17:10 +0800 CST2018-02-05 08:17:10 +0800 CST 2018-02-05 08:17:10 +0800 CST

ss 命令为每个结果占用 2 行

  • 772

我曾经netstat -anlptu检查开放的端口。
这个命令现在有点弃用了,所以我开始使用ss -anptu,但每个条目需要 2 行。结果是不切实际的。
我使用 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))

这显然不容易阅读。
某些列未对齐。

 

如果我重定向到lessor 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?

networking command-line
  • 1 1 个回答
  • 396 Views

1 个回答

  • Voted
  1. Best Answer
    cas
    2018-02-05T08:29:10+08:002018-02-05T08:29:10+08:00

    使用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 列宽的终端(在我的 1440p 屏幕上使用 Liberation Mono Regular 11 的最大宽度终端)。YMMV 在较窄的终端上。

    column执行columns与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文件说:

    这是来自 4.4BSD-Lite 的程序集合,尚未(还)被 FSF 重写为 GNU。它是为包含在 Debian Linux 中而构建的。当此处找到的程序可从 GNU 源获得时,它们将被替换。

    和

    此软件包可根据 UCB BSD 许可条款重新分发:

    版权所有 (C) 1980 -1998 加州大学董事会。版权所有。

    • 2

相关问题

  • 远程运行 X 应用程序,在远程主机上运行 GUI [关闭]

  • 无法识别arp命令或ip命令哪个MAC地址输出正确

  • 使 mysql CLI 以交互方式向我询问密码

  • 奇怪的路由器与centos 6一起工作[关闭]

  • 没有服务器的命令行 pub/sub?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve