Haikson

[ Everything is possible. Everything takes time. ]

How to check busy ports on Linux and MacOS

If, when starting an application, you receive errors indicating that port X is busy, here is a port checking script to help you

For Linux

#/bin/bash
filter=${1:-""}
netstat -tulpn | awk -vq="$filter" -vOFS='\t' '$0!~q{next} /^tcp/{print $4,$7} /^udp/{print $4,$6}'

For MacOS

#/bin/bash
filter=${1:-""}
netstat -anvp tcp | awk 'NR<3 || /LISTEN/' | awk -vq="$filter" -vOFS='\t' '$0!~q{next} /^tcp/{print $4,$11} /^udp/{print $4,$11}'