5

I'm far used to the output of netstat -taulpen, and although I don't know what all the flags do specifically, it gives a nice readable table of networking programs, and when run as sudo can show all process names inline with the address and socket they listen on etc.

With ss I get close with:

$ 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

As you can imagine this gives output like this: I've manually wrapped the lines as they appear in the terminal output:

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))

So my problem is I have a lot of space in my terminal emulator, but ss is very firm on wrapping the first few columns to 100% width, and the remaining columns fall off and wrap, even though there is no literal newline shown in xxd.

1
  • 2
    Use column : ss -tlnp | column -t . If it bothers you that the header line is not correctly aligned (because the headers contain spaces), you can suppress it with the -H option or with sed. So ss -H -tlnp | column -t or ss -tlnp | sed 1d | column -t
    – mivk
    Commented Sep 15, 2019 at 12:16

1 Answer 1

5

1) Pipe though a program that strips the tty width context, like 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))

2) Lie about your tty width with stty:

I don't consider this a solution because it involves manually modifying the environment to achieve an effect in a program's context.

But this does work, thought I will never bother to use it:

# 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))
2
  • The cat solution unfortunately breaks table - local address is no longer aligned to the left and all columns after are not aligned (randomly shifted left/right) as well :-(. Tested on fresh CentOS 7.
    – monnef
    Commented May 18, 2016 at 6:13
  • It's important to note that if you still can't see the users information, you're probably not running ss as root. It needs to be run with escalated privileges in order to show you the user process. Commented Jan 30, 2019 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .