Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lsof print numeric ports

Tags:

unix

tcp

ports

lsof

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.

like image 847
Coder Guy Avatar asked Dec 01 '15 23:12

Coder Guy


People also ask

What does lsof return?

The lsof (list open files) command returns the user processes that are actively using a file system. It is sometimes helpful in determining why a file system remains in use and cannot be unmounted.


2 Answers

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."

like image 90
kwarunek Avatar answered Sep 19 '22 13:09

kwarunek


Sometimes handy is:

lsof -Pi 

When I tried losf -iP it gave me some trash, so make sure P goes first.


As a side note: lsof -3.14 will provide the same trash, don't try this.

like image 42
prosti Avatar answered Sep 21 '22 13:09

prosti