lsof Cheat Sheet
List open files — which process holds a port, opened a deleted file, or is bleeding disk space.
Troubleshooting3 sections · 15 commands
⌘K
Ports & Network
6lsof -iTCP:443Who is listening on port 443
lsof -i :8080Any protocol on 8080
lsof -iTCP -sTCP:ESTABLISHEDEstablished connections
lsof -iUDPUDP sockets
lsof -iEvery network file
lsof -iTCP@hostConnections to a host
By Process & User
6lsof -p PIDAll open files of a process
lsof -u USERFiles opened by a user
lsof -c nginxProcesses whose name matches
lsof -a -p PID -iAND both filters
lsof +D DIRFiles under a directory (recursive)
lsof | grep nginxGrep the whole table
Deleted & Disk
3lsof +L1Deleted files still open (disk leak)
lsof +L1 | awk '{print $7}' | sort | uniq -c | sort -rn | headBiggest deleted-file holders
lsof -nPNo name resolution (faster)