在 Ubuntu 可以使用 lsof 搭配 grep 列出正在使用的 port
1 | sudo lsof -i -P -n | grep LISTEN |
lsof: List Open Files, 列出開啟的檔案
-i: 列出被開啟的網路檔案
-P: 列出 port number (避免 lsof 使用 service name)
-n: 列出 IP address (避免 lsof 使用 hostname)
| grep LISTEN: 將 lsof 指令結果導入 grep, grep LISTEN 則找出目前正在使用的 port