- 浏览: 134725 次
- 性别:
- 来自: 成都
文章分类
最新评论
【基本介绍】
lsof - list open files
It is a command line utility which is used to list the information about the files that are opened by various processes. In unix, everything is a file, ( pipes, sockets, directories, devices, etc.). So by using lsof, you can get the information about any opened files.所有的东西都是文件,lsof用来查看打开文件的进程
【参数介绍】
FD – Represents the file descriptor.(文件描述) Some of the values of FDs are,
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ’1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.
TYPE – Specifies the type of the file.(文件类型) Some of the values of TYPEs are,
REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file
lsof filename 显示打开指定文件的所有进程
lsof -a 表示两个参数都必须满足时才显示结果
lsof -c string 显示COMMAND列中包含指定字符的进程所有打开的文件
lsof -u username 显示所属user进程打开的文件
lsof -g gid 显示归属gid的进程情况
lsof +d /DIR/ 显示目录下被进程打开的文件
lsof +D /DIR/ 同上,但是会搜索目录下的所有目录,时间相对较长
lsof -d FD 显示指定文件描述符的进程
lsof -n 不将IP转换为hostname,缺省是不加上-n参数
lsof -i :port 显示使用端口的进程
【常用例子】
List processes which opened a specific file(显示打开指定文件的进程)
List all open files by a specific process(显示指定进程IP)
List processes which are listening on a particular port(显示指定端口)
List files opened by a specific user(显示指定用户的进程)
List opened files based on process names starting with(显示指定进程名)
List opened files under a directory(显示目录下被打开的文件)
【参考引用】
http://blog.csdn.net/guoguo1980/article/details/2324454
http://www.thegeekstuff.com/2012/08/lsof-command-examples/
lsof - list open files
It is a command line utility which is used to list the information about the files that are opened by various processes. In unix, everything is a file, ( pipes, sockets, directories, devices, etc.). So by using lsof, you can get the information about any opened files.所有的东西都是文件,lsof用来查看打开文件的进程
【参数介绍】
[root@pandaVM ~]# lsof | head -10 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root cwd DIR 8,2 4096 2 / init 1 root rtd DIR 8,2 4096 2 / init 1 root txt REG 8,2 150352 130349 /sbin/init init 1 root mem REG 8,2 65928 260653 /lib64/libnss_files-2.12.so init 1 root mem REG 8,2 1926800 264737 /lib64/libc-2.12.so init 1 root mem REG 8,2 93320 264762 /lib64/libgcc_s-4.4.7-20120601.so.1 init 1 root mem REG 8,2 47064 264739 /lib64/librt-2.12.so init 1 root mem REG 8,2 145896 260719 /lib64/libpthread-2.12.so init 1 root mem REG 8,2 268232 264740 /lib64/libdbus-1.so.3.4.0
FD – Represents the file descriptor.(文件描述) Some of the values of FDs are,
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ’1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.
TYPE – Specifies the type of the file.(文件类型) Some of the values of TYPEs are,
REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file
lsof filename 显示打开指定文件的所有进程
lsof -a 表示两个参数都必须满足时才显示结果
lsof -c string 显示COMMAND列中包含指定字符的进程所有打开的文件
lsof -u username 显示所属user进程打开的文件
lsof -g gid 显示归属gid的进程情况
lsof +d /DIR/ 显示目录下被进程打开的文件
lsof +D /DIR/ 同上,但是会搜索目录下的所有目录,时间相对较长
lsof -d FD 显示指定文件描述符的进程
lsof -n 不将IP转换为hostname,缺省是不加上-n参数
lsof -i :port 显示使用端口的进程
【常用例子】
List processes which opened a specific file(显示打开指定文件的进程)
# lsof /var/log/syslog COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsyslogd 488 syslog 1w REG 8,1 1151 268940 /var/log/syslog
List all open files by a specific process(显示指定进程IP)
# lsof -p 1753 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1753 lakshmanan cwd DIR 8,1 4096 393571 /home/lakshmanan/test.txt bash 1753 lakshmanan rtd DIR 8,1 4096 2 / bash 1753 lakshmanan 255u CHR 136,0 0t0 3 /dev/pts/0
List processes which are listening on a particular port(显示指定端口)
# lsof -i :25 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME exim4 2541 Debian-exim 3u IPv4 8677 TCP localhost:smtp (LISTEN)
List files opened by a specific user(显示指定用户的进程)
# lsof -u lakshmanan COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME update-no 1892 lakshmanan 20r FIFO 0,8 0t0 14536 pipe update-no 1892 lakshmanan 21w FIFO 0,8 0t0 14536 pipe bash 1995 lakshmanan cwd DIR 8,1 4096 393218 /home/lakshmanan
List opened files based on process names starting with(显示指定进程名)
# lsof -c ssh -c init COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root txt REG 8,1 124704 917562 /sbin/init init 1 root mem REG 8,1 1434180 1442625 /lib/i386-linux-gnu/libc-2.13.so init 1 root mem REG 8,1 30684 1442694 /lib/i386-linux-gnu/librt-2.13.so ... ssh-agent 1528 lakshmanan 1u CHR 1,3 0t0 4369 /dev/null ssh-agent 1528 lakshmanan 2u CHR 1,3 0t0 4369 /dev/null ssh-agent 1528 lakshmanan 3u unix 0xdf70e240 0t0 10464 /tmp/ssh-sUymKXxw
List opened files under a directory(显示目录下被打开的文件)
# lsof +D /var/log/ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsyslogd 488 syslog 1w REG 8,1 1151 268940 /var/log/syslog rsyslogd 488 syslog 2w REG 8,1 2405 269616 /var/log/auth.log console-k 144 root 9w REG 8,1 10871 269369 /var/log/ConsoleKit/history
【参考引用】
http://blog.csdn.net/guoguo1980/article/details/2324454
http://www.thegeekstuff.com/2012/08/lsof-command-examples/
发表评论
-
linux shell - 远端修改非root密码
2015-01-09 20:40 954【基本介绍】 通过远端修改普通用户密码,而passwd --s ... -
linux shell - broken pip error
2015-01-07 15:36 2664【基本介绍】 这里我们介绍发生broken pipe错误的原因 ... -
linux locate - find files by name
2014-12-17 17:46 559【基本介绍】 这里我们介绍locate命令,用来查找文件。 ... -
linux ssh - GSSAPIAuthentication
2014-12-10 14:58 2000【基本介绍】 最近公司搬家,发现合作伙伴的服务器的用ftp工具 ... -
linux tar - 压缩解压
2014-12-01 16:04 969【基本介绍】 今天遇到要添加文件到tar文件里面,所以在这里介 ... -
linux parameter substitution - 字符串/变量处理
2014-11-17 15:56 777【基本介绍】 这里我们介绍bash里面对字符串,变量等的替换等 ... -
linux netstat - status状态描述
2014-11-14 17:59 1112【基本介绍】 这里介绍netstat命令返回的结果status ... -
linux set - set variables and set positional parameters
2014-11-10 18:26 406【基本介绍】 set是shell的内置命令。可以用来设置修改变 ... -
linux nc - arbitrary TCP and UDP connections and listens
2014-10-31 17:46 758【基本介绍】 nc是可以打开任意端口的TCP/UDP连接和监听 ... -
linux 报错集 - Cannot retrieve metalink for repository: epel. Please verify its pat
2014-10-29 15:12 925【基本介绍】 运行yum报错Error: Cannot ret ... -
linux awk - awk tutorial
2014-10-21 10:47 457【基本介绍】 awk是一款强大的对文件内容进行处理的软件,可以 ... -
linux ps - processes
2014-10-20 14:17 1219【基本介绍】 ps - report a snapshot o ... -
linux - 网络连接状态
2014-10-13 11:00 1349【基本情况】 这里介绍 ... -
linux netstat - Print network connections, routing tables, interface statistics,
2014-10-13 10:37 978【基本介绍】 netstat - Print network ... -
linux vmstat - Report virtual memory statistics
2014-10-10 17:39 691【基本介绍】 vmstat - Report virtual ... -
linux yum - yum warning: rpmts_HdrFromFdno
2014-10-09 15:08 560【基本介绍】 在yum安装软件的时候有时候会报warning: ... -
Linux ip subnet mask - 网段分析
2014-09-24 19:22 1292【基本介绍】 网段的分析可以帮助我们查看两个局域地址是否可以互 ... -
linux curl - curl 上传下载
2014-09-19 11:45 2074【基本介绍】 curl is a tool to tra ... -
linux mkpasswd - 密码生成器
2014-09-18 17:18 1380【基本介绍】 作为linux admin要经常创建用户,并初始 ... -
linux dd - dd测试硬盘速度
2014-09-05 18:42 815【基本介绍】 这里我们使用dd命令来测试硬盘的读写速度 dd ...
相关推荐
yum版本 lsof-i:单口号 可查询端口使用情况。如:lsof -i:80
lsof-4.87-6.el7.x86_64.rpm centos7.4 lsof
适于用linux centos 版本的操作系统,rpm格式的文件安装简单快捷
lsof for solaris10 x86
lsof-4.61-4 for aix5.3
./Configure aix 或者 aixgcc make make install 注意要用ROOT
Linux 下 lsof 命令的 man page 中文翻译,带目录。 lsof 可以列出当前系统打开的任何文件,选项众多,自带的-h帮助非常精简。 自带 man page 复制到doc文档有50页,没有目录非常不方便查阅。
lsof arm-linux-gnueabihf-gcc 可执行程序
lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.
lsof-4.87-6.el7.x86_64.rpm.7z
lsof-4.82-4.el6.i686.rpm ,32位,centos6系列的
主要给大家介绍了关于在linux中利用lsof命令如何查看文件打开情况的相关资料,文中通过示例代码以及图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
交叉编译完成的lsof命令,适合在arm-cpu架构的服务器上使用
下面小编就为大家带来一篇Linux查看端口占用lsof -i:port的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
这是Linux 下lsof v4.91版本的英文man手册,添加章节目录,以便查阅。 lsof 可以列出当前系统打开的任何文件,选项众多,自带的-h帮助非常精简。 自带 man page 复制到doc文档有50页,没有目录非常不方便查阅。
hpux lsof安装包
linux lsof命令详解.docx
linux lsof源码