https://apple.stackexchange.com/a/117648/495485
**`netstat -anvp tcp | awk 'NR<3 || /LISTEN/'`**
This command makes netstat dump all the ports (-a) as numbers (-n) on the given protocol (-p tcp or udp) as an extended table (-v), and then filters the table with awk to include the table header and all rows passing the given regex.
```
-a
-n numeric ports
-v
-p tcp TCP only
```
**`sudo lsof -PiTCP -sTCP:LISTEN`**
**`sudo netstat -tulpn | grep LISTEN`**
Where,
- **-t** : All TCP ports
- **-u** : All UDP ports
- **-l** : Display listening server sockets
- **-p** : Show the PID and name of the program to which each socket belongs
- **-n** : Don’t resolve names
- **| grep LISTEN** : Only display open ports by applying grep command filter.
#netstat #networking #linux