lsof print numeric ports

Jonathan Neufeld picture Jonathan Neufeld · Dec 2, 2015 · Viewed 37.1k times · Source

How do you get lsof to produce numeric port information instead of attempting to resolve the port to service name?

For example, I want TCP *:http (LISTEN) to give me TCP *:80 (LISTEN) in-fact if at all possible I never want to see another service name in lsof print-out ever again. So if there is a way to make numeric ports the default I would like to understand how to do that as well.

Answer

kwarunek picture kwarunek · Dec 2, 2015

Run lsof -P. According to man lsof, -P inhibits the conversion of port numbers to port names for network files. Inhibiting the conversion may make lsof run a little faster. It is also useful when port name lookup is not working properly."