In depsite of people got used to netstat
for such kind of operations, it's good to know, that Linux has another great (and, actually superior) networking tool — ss
. For e. g., to find out which process has opened port 80 you run it so:
sudo ss -pt state listening 'sport = :80'
so there's no need to pipe through external filters. Surely it has lots more useful knobs, so get yourself familiar with it.
For completeness sake and since recently I came across man fuser
, I can also mention:
sudo fuser 80/tcp
— this one also saves you from tinkering at cut
/grep
/awk
… keep in mind this notation is a short-cut, in case there's an ambiguity, you should use one of namespaces allowed with -n …
, like sudo fuser -n tcp 80
sudo lsof -n -sTCP:LISTEN -i:80
— was pointed out by @wallenborn. Meanwhile -n
is not strictly required it's strongly advised since otherwise it uses DNS resolving which usualy slows down output terribly.