【Linux】常用命令 lsof查看打开的文件

本文介绍了Linux系统中如何利用文件来追踪软硬件信息,包括显示打开文件的进程、占用特定端口的进程、以及查看指定进程或进程号、用户的打开文件等方法,并详细解析了lsof命令的常用用法及输出字段解释。

Linux系统把软硬件都抽象成文件,所以通过文件可以追踪到很多重要信息,如读取的配置文件、打开的端口等。

下面是常见的用法:

默认测试文件名为text.txt

1,显示打开text.txt的进程:

lsof text.txt

2,显示占用某个端口的进程:

lsof -i :80

3,显示某个进程(进程名)打开的文件:

lsof -c process_name

4,显示某个进程号(pid)打开的文件:

lsof -p pid_number

5,显示某个用户打开的文件:

lsof -u user_name

默认输出字段解释:

[groot]$lsof -u groot
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

COMMAND:进程名字(默认下只取前9个字符);

PID:Process IDentification number;

USER:the user ID number or login name of the user to whom the process belongs;

FD:File Descriptor number or

  cwd current working directory;

  ltx   shared library text(code and data);

  mem memory-mapped file;

  mmap memory-mapped device;

  pd   parent directory;

  rtd   root directory;

  txt   program text(code and data);

TYPE:is the type of the node associated with the file - e.g., GDIR, GREG, VDIR, VREG, etc.

 

转载于:https://www.cnblogs.com/buffalo/p/4787550.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值