需要安装lsof工具 比如查8999端口: lsof -i:8999|awk '{if(NR>1) print $2}' 如果返回空表示没被占用 转载于:https://blog.51cto.com/zl1030/1660393