Skip to content


lsof常用技巧

1) lsof abc.txt 显示开启文件abc.txt的进程
2) lsof -i :22 知道22端口现在运行什么程序
3) lsof -c nsd 显示nsd进程现在打开的文件
4) lsof -g gid 显示归属gid的进程情况
5) lsof +d /usr/local/ 显示/usr/local目录下被进程开启的文件
6) lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长
7) lsof -d 4 显示使用fd为4的进程
8) lsof -i [i] 用以显示符合条件的进程情况
语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
46 –> IPv4 or IPv6
protocol –> TCP or UDP
hostname –> Internet host name
hostaddr –> IPv4位置
service –> /etc/service中的 service name (可以不只一个)
port –> 端口号 (可以不只一个)
例子: TCP:25 – TCP and port 25
@1.2.3.4 – Internet IPv4 host address 1.2.3.4
[email protected]:ftp – TCP protocol host:ohaha.ks.edu.tw service name:ftp
9) lsof -n 不将IP转换为hostname,缺省是不加上-n参数
例子: lsof -i [email protected]:ftp -n
10) lsof -p 12 看进程号为12的进程打开了哪些文件
11) lsof +|-r [t] 控制lsof不断重复执行,缺省是15s刷新
-r,lsof会永远不断的执行,直到收到中断信号
+r,lsof会一直执行,直到没有档案被显示
例子:不断查看目前ftp连接的情况:lsof -i [email protected]:ftp -r
12) lsof -s 列出打开文件的大小,如果没有大小,则留下空白
13) lsof -u username 以UID,列出打开的文件

Posted in Linux 命令, 技术.

Tagged with .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.