Chinaunix

标题: lsof 用法小全 [打印本页]

作者: jsjxiaosan    时间: 2008-09-06 17:15
标题: lsof 用法小全
lsof abc.txt 显示开启文件 abc.txt 的进程
lsof -i :22 知道 22 端口现在运行什么程序
lsof -c nsd  显示 nsd 进程现在打开的文件
lsof -g gid 显示归属 gid 的进程情况
lsof +d /usr/local/  显示目录下被进程开启的文件
lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长
lsof -d 4   显示使用 fd 为4 的进程
lsof -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=tcp@ohaha.ks.edu.tw:ftp]tcp@ohaha.ks.edu.tw:ftp[/email]
- TCP protocol host:ohaha.ks.edu.tw service name:ftp
lsof -n 不将 IP转换为 hostname,预设是不加上-n参数
例子: lsof -i
[email=tcp@ohaha.ks.edu.tw:ftp]tcp@ohaha.ks.edu.tw:ftp[/email]
-n
lsof -p 12   看进程号为 12的进程打开了哪些文件     
54/65
Linux 一句话精彩问答/陈绪  
http://www.linuxpk.com

lsof +|-r [t] 控制 lsof不断重复执行,缺省是 15s 刷新
-r,lsof会永远不断的执行,直到收到中断讯号
+r,lsof会一直执行,直到没有档案被显示
例子:不断查看目前 ftp连接的情况:lsof -i
[email=tcp@ohaha.ks.edu.tw:ftp]tcp@ohaha.ks.edu.tw:ftp[/email]
-r
lsof -s  列出打开文件的大小,如果没有大小,则留下空白
lsof -u username   以 UID,列出打开的文件

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/78534/showart_1167874.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2