8

Is it possible to output full command name with lsof -nP -i4UDP?

I've been looking in the manual for a suitable option, like -V (see below), but it doesn't result in full COMMAND names, i.e. systemd-resolve is displayed as systemd-r:

$ sudo lsof -V -nP -i4UDP
COMMAND    PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
avahi-dae  437           avahi   12u  IPv4  12982      0t0  UDP *:5353 
avahi-dae  437           avahi   14u  IPv4  12984      0t0  UDP *:45006 
cups-brow  449            root    7u  IPv4  12149      0t0  UDP *:631 
systemd-r  485 systemd-resolve   12u  IPv4  14694      0t0  UDP 127.0.0.53:53 
systemd-r  485 systemd-resolve   13u  IPv4  14695      0t0  UDP *:5355 
dhclient   629            root    6u  IPv4  14985      0t0  UDP *:68 
minissdpd 1186            root    4u  IPv4  19639      0t0  UDP *:1900 

1 Answer 1

9

From man lsof:

+c w     defines the maximum number of initial characters of the name,
         supplied by the UNIX dialect, of the UNIX command associated with a
         process to be printed in the COMMAND  column.  (The lsof default is nine.)

         Note  that  many UNIX dialects do not supply all command name characters
         to lsof in the files and structures from which lsof obtains command name.
         Often  dialects limit the number  of characters supplied in those sources.
         For example, Linux 2.4.27 and Solaris 9 both limit command name length to
         16 characters.

         If w is zero ('0'), all command characters supplied to lsof by the UNIX
         dialect will be printed.

         If  w  is  less  than the length of the column title, ``COMMAND'', it will
         be raised to that length.

Given that, you can add +c0 to get all that are available:

$ sudo lsof -V -nP -i4UDP +c0
COMMAND         PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-resolve 176 systemd-resolve   11u  IPv4  11204      0t0  UDP *:5355
3
  • Thanks Andy! Do you know what's the purpose of -V? Also, UNIX dialect should be understood as the underlying OS, e.g. Linux or macOS, from which lsof obtains the COMMAND column information?
    – Shuzheng
    Jun 29, 2020 at 18:33
  • @Shuzheng See man lsof for info on -V: man7.org/linux/man-pages/man8/lsof.8.html . Yes, UNIX dialect means the underlying OS. Jun 29, 2020 at 19:12
  • 2
    Note that, in any case, what's reported here is the process name (same as in ps -o comm or ps alone) which on Linux is limited to 15 bytes in length (which explains why systemd-resolved is truncated to systemd-resolve here). Jun 29, 2020 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.