“lsof” command

Just found out about this command today.

“lsof” displays information about open files by processes on *nix systems (including network “files” – TCP/UDP). I don’t know how I managed to miss such a useful command over the years.

As an example, listing network ports (which I would previously have done with netstat):

# lsof +c0 -n | grep IP 

java             1022    martinm   28u     IPv6
          467902                 TCP 192.168.2.104:51769->192.168.10.1:xmpp-client (ESTABLISHED)
java             2961    martinm    6u     IPv6
          322274                 TCP *:8083 (LISTEN)
evolution        6408    martinm   59u     IPv6
          472527                 TCP [fffe:111:11:2:111:72ff:fe10:2bd]:51943->[fffe:111:11:1::11]:imaps (ESTABLISHED)
mysql           18407    martinm    3u     IPv4
          489375                 TCP 192.168.2.104:49021->192.168.2.146:mysql (ESTABLISHED)
firefox-bin     24396    martinm   52u     IPv4
          490170                 TCP 192.168.2.104:52906->192.168.0.1:webcache (ESTABLISHED)

I added linebreaks to make it more readable
As usual, further information is available with man lsof.
Now I’ll just need to find out a way of setting the command to be the Java Start Class to identify which java program has the port open.

Update: the number after the command is the PID so a ps -fpXXXX will show the comamnd line.

This entry was posted in Networks, Security, Software, Work. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

You must be logged in to post a comment.