linux上经常会查找某个服务的路径在哪里,如果通过,如查找nginx
find / -name nginx
会在服务器上查找到一堆目录下都有这个文件
现在要查找的是此刻正在运行的服务的目录。
如查找nginx运行的目录
1、先通过nginx的PID,以常用的80端口为例。
netstat -anop | grep 0.0.0.0:80
2、通过相应的进程ID(比如4562)查询当前运行的nginx路径:
ll /proc/4562/exec
获取到的结果如下
lrwxrwxrwx 1 root root 0 7月 24 09:14 /proc/7968/exe -> /opt/service/nginx/sbin/nginx
这样就可以查询到服务所在的位置了/opt/service/nginx