lsof Cheatsheet - Linux Process & Port Diagnostics Reference

Lsof's core strength is reversing the questions — give it a port and it names the process, give it a user and it lists every open file. Port-already-in-use, file-held-by-an-old-process, and disk-space-not-released are all the same root cause, a lingering open handle; this table groups lookups by axis and adds +L1 for the deleted-file case so the usual suspects surface quickly.

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

By Process 6

lsof -p 1234
Files opened by a given PID
lsof -c nginx
Files opened by the nginx process
lsof -c /^nginx/
Match process name by regex
lsof -u tom
Files opened by a given user
lsof -u ^root
Exclude the root user
lsof -p 1234,5678
Files opened by multiple PIDs

By Port 6

lsof -i :80
Process using port 80
lsof -i :8080 -i :8443
Check multiple ports
lsof -i tcp:80
TCP port 80 only
lsof -i udp:53
UDP port 53 only
lsof -i @192.168.1.1:80
Specific IP and port
lsof -i :1-1024
All privileged ports (1-1024)

By File 4

lsof /var/log/syslog
Who opened a given file
lsof +D /var/log/
All open files under a directory (recursive)
lsof +d /var/log/
Current directory only (non-recursive)
lsof /dev/sda1
Who is using a given device

Network 8

lsof -i
All network connections
lsof -i -n
No name resolution (faster)
lsof -i -P
No port-name resolution (numeric ports)
lsof -i -n -P
Combined (fastest)
lsof -i tcp@192.168.1.1:22
SSH connections to a host
lsof -i -sTCP:ESTABLISHED
Established connections only
lsof -i 4 -P -n
IPv4 connections only (no resolution)
lsof -i 6 -P -n
IPv6 connections only

By Type / Format 4

lsof -t
Output PIDs only (good for pipes)
lsof -F pfc
Output formatted fields (PID/command/user)
lsof -a -p 1234 -c nginx
AND-combine conditions
lsof -Or -p 1234 -p 5678
OR-combine conditions

Troubleshooting 7

lsof -i :80 | grep LISTEN
Find the process listening on port 80
lsof +L1
Deleted-but-open files (when disk is full)
lsof -nP -iTCP -sTCP:LISTEN
All listening TCP ports
lsof -i :22 | grep ESTABLISHED
Established SSH connections
lsof -u tom | wc -l
Count files opened by a user
kill $(lsof -t -i :8080)
Kill the process occupying port 8080
lsof -i :80 -r 5
Monitor port 80 every 5 seconds

Tips

  • lsof needs root to see all users' files; ordinary users see only their own.
  • For port conflicts, first find the PID with lsof -i :port, then kill it or change config.
  • When the disk is full but no large file shows, use lsof +L1 to find deleted-but-open files.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

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

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us