ss - linux socket statistics utility output format

Following one might be helpful to change output:

ss -ltunp | column -t 

As for why etc.

ss, part of the iproute2 utility collection in the Linux kernel, uses an ioctl() request to get the current width of terminal.

However; the entire width is used for the «other» fields and the process field get squeezed onto next line.

You can view this by for example (when having a limited with on terminal):

script ss.txt
ss -nlup4
exit

Then widen your terminal window and cat ss.txt.

The reason why

ss -nulp4 | cat -A

«works» is because the utility recognizes if it writes to a tty or not:

if (isatty(STDOUT_FILENO)) {

}

As you can see from the prior line in the source code default width is set to 80. Thus if your terminal is at say 130 columns and you do:

ss -nulp4 | cat

it recognizes the output is not to a tty (but to a pipe) and the other fields are crammed into 80 columns, whilst the process field is written after these 80 columns. But as your terminal is wider then 80 columns and has room for the process entry it is displayed in one line.

The same goes for for example:

ss -nulp4 > ss.txt

As for how to «achieve my preferred formatting» one likely unsuitable way is to do something in the direction of (depending on terminal):

stty cols 100
ss -nlup4