lsof is short of "LiSt Open Files". Among other things, these open files include network files like internet sockets, UNIX domain sockets, etc.
lsof
flags
-
-i
By itself, it will list all the open internet and network files. Otherwise, it will attempt to match the provided argument, which should be an internet address specified as follows:
[46][protocol][@hostname|hostaddr][:service|port]
. E.g.,:3000
. -
-n
Tells
lsof
to not convert IP addresses to hostnames. The lookup times for the hostnames can drastically affect the time it takes to runlsof
. I'm guessing this is because thelsof
service has to reach out to the internet and check DNSs until it finds one that knows the hostname of the IP address it's checking against. -
-t
List tersely. I.e., it lists just the PIDs.
lsof
Examples
-
lsof -i :3000
will list every open network file listening on port :3000 -
lsof -nti :3000
will list just the PIDs listening on port :3000 -
lsof -n | grep LISTEN
will list every listening process/open-file