lsof Cheatsheet - Linux Process & Port Diagnostics Reference

All essential lsof commands organized by use case, with 35+ entries you can copy and run directly. Find the right command fast when you need it.

SysOps·35 commands·Last updated 2026-07-21
Back to SysOps

By Process 6

lsof -p 1234
Show指定 PID Open的File
lsof -c nginx
Show nginx ProcessOpen的File
lsof -c /^nginx/
正则MatchProcess名
lsof -u tom
Show指定UserOpen的File
lsof -u ^root
排除 root User
lsof -p 1234,5678
Show多个ProcessOpen的File

By Port 6

lsof -i :80
Showusage 80 Port的Process
lsof -i :8080 -i :8443
Show多个Port
lsof -i tcp:80
只Show TCP 80 Port
lsof -i udp:53
只Show UDP 53 Port
lsof -i @192.168.1.1:80
Show指定 IP 和Port
lsof -i :1-1024
Show所有特权Port(1-1024)usage

By File 4

lsof /var/log/syslog
Show谁Open了指定File
lsof +D /var/log/
ShowDirectory下所有Open的File
lsof +d /var/log/
只Show当前Directory(不recursively)
lsof /dev/sda1
Show谁在使用指定设备

Network 8

lsof -i
Show所有NetworkConnection
lsof -i -n
不解析域名(更快)
lsof -i -P
不解析Port名(Display数字Port)
lsof -i -n -P
组合使用(最快)
lsof -i tcp@192.168.1.1:22
Show到指定主机的 SSH Connection
lsof -i -sTCP:ESTABLISHED
只Show已建立的Connection
lsof -i 4 -P -n
只Show IPv4 Connection(不解析加速)
lsof -i 6 -P -n
只Show IPv6 Connection

By Type 4

lsof -t
只Output PID(方便pipe处理)
lsof -F pfc
Output格式化的field(PID/命令/User)
lsof -a -p 1234 -c nginx
AND 组合condition
lsof -Or -p 1234 -p 5678
OR 组合condition

Troubleshooting 7

lsof -i :80 | grep LISTEN
Show 80 Port监听Process
lsof +L1
Show已Delete但仍被Open的File(Disk满时用)
lsof -nP -iTCP -sTCP:LISTEN
Show所有监听中的 TCP Port
lsof -i :22 | grep ESTABLISHED
Show已建立的 SSH Connection
lsof -u tom | wc -l
统计UserOpen的File数
kill $(lsof -t -i :8080)
一键杀掉usage 8080 Port的Process
lsof -i :80 -r 5
每 5 秒重复监控 80 Port

💡 Tips

  • lsof 需要 root Permission才能Show所有User的File,普通User只能看自己的。
  • Portusage排查:先用 lsof -i :port 找到 PID,再用 kill Kill process或改Configure。
  • Disk满但找不到大File时,用 lsof +L1 找已Delete但仍被Processusage的File。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it