list all listening ports on a mac

last updated: Jun 17, 2024

The always excellent Julia Evans notes a better command to list all listening ports and the process listening to them on a mac. sudo lsof -i -P is often given as a command to use, but it is very slow and hangs for a long time.

She suggests sudo lsof -iTCP -sTCP:LISTEN -iUDP -n -P instead.

I've hit this problem before; when debugging this issue, somebody suggested lsof -I -T f | grep 8888 and it was super slow; eventually I found that lsof -i :8888 -T f was much faster.

I don't truly understand what lsof is doing though.

↑ up