List open ports with lsof

lsof is very useful to get a quick grip of the current open ports on your machine. It can do much more, the name is short for “list open files”. You can see exactly which files are open and which process that opened them.

This lists all open files that are connecting over the network:

lsof -i -P

To filter out the open ports, use grep

lsof -i -P | grep -i "listen"