查看打开的文件和相应的进程。
注意:查看其他用户打开的文件需要root权限。
- 找到打开文件的进程:
lsof {{path/to/file}}
- 找到指定端口的进程:
lsof -i :{{port}}
- 只输出进程ID(PID):
lsof -t {{path/to/file}}
- 查看用户打开的文件:
lsof -u {{username}}
- 查看由命令或进程打开的文件:
lsof -c {{process_or_command_name}}
- 查看指定进程打开的文件:
lsof -p {{PID}}
- 查看目录中的打开文件:
lsof +D {{path/to/directory}}