lsof File Descriptor Cheatsheet
lsof (List Open Files) is an essential diagnostic tool on Linux/Unix systems for listing open files, pipes, network connections, and other resources. This cheatsheet covers basic usage, network troubleshooting, user/process analysis, and advanced techniques, including fuser and /proc filesystem utilities.
Updated: 2026-07-17·27 commands
Overview
lsof (List Open Files) is a command-line utility that lists information about files opened by processes. In Unix/Linux, everything is a file, making lsof an invaluable troubleshooting tool.
Quick Start
``bash
lsof -i :80 # Find what's listening on port 80
lsof -u username # List files opened by a user
lsof -p PID # List files opened by a process
``
Refer to the command table below for detailed usage.
Basic(8)
| Command | Level | ||
|---|---|---|---|
lsofList all open files on the system | Basic | lsof | |
lsof +D /pathRecursively list open files under a directory | Intermediate | lsof +D /var/log | |
lsof /path/to/fileCheck which processes are using a file | Basic | lsof /var/log/syslog | |
lsof -n -PSkip DNS and port name resolution (faster output) | Intermediate | lsof -n -P -i | |
ls -la /proc/PID/fd/View process file descriptors via /proc | Intermediate | ls -la /proc/1234/fd/ | |
ls -la /proc/PID/cwdView process current working directory | Intermediate | ls -la /proc/1234/cwd | |
ls -la /proc/PID/exeView process executable path | Intermediate | ls -la /proc/1234/exe | |
readlink /proc/PID/fd/NCheck what a specific FD points to | Intermediate | readlink /proc/1234/fd/3 |
Network(8)
| Command | Level | ||
|---|---|---|---|
lsof -iList all network connections (IPv4/IPv6) | Basic | lsof -i | |
lsof -i :portCheck connections on a specific port | Basic | lsof -i :8080 | |
lsof -i :port1-port2Check a port range | Intermediate | lsof -i :8000-8100 | |
lsof -iTCP -sTCP:LISTENList all TCP listening sockets | Intermediate | lsof -iTCP -sTCP:LISTEN | |
lsof -iUDPList all UDP connections | Intermediate | lsof -iUDP | |
lsof -i @hostFilter by host/IP address | Intermediate | lsof -i @192.168.1.1 | |
lsof -i -sTCP:LISTEN -n -PListen sockets without DNS/port resolution (common combo) | Intermediate | lsof -i -sTCP:LISTEN -n -P | |
lsof -iTCP -sTCP:ESTABLISHED -n -PView established TCP connections | Intermediate | lsof -iTCP -sTCP:ESTABLISHED -n -P |
User & Process(5)
| Command | Level | ||
|---|---|---|---|
lsof -u userList open files for a specific user | Basic | lsof -u admin | |
lsof -u ^userExclude files of a specific user | Intermediate | lsof -u ^root | |
lsof -c processFind files by process name prefix | Basic | lsof -c nginx | |
lsof -p PIDView open files for a specific PID | Basic | lsof -p 1234 | |
lsof -p PID1,PID2View open files for multiple PIDs | Intermediate | lsof -p 1234,5678 |
Advanced(6)
| Command | Level | ||
|---|---|---|---|
lsof -FParseable output format (for scripting) | Expert | lsof -F pcfn | |
lsof | grep DELFind deleted files still consuming disk space | Expert | lsof | grep DEL | |
lsof -a -u user -iAND condition combination (user and network) | Expert | lsof -a -u admin -i :3000 | |
fuser /path/to/fileShow PIDs using a specific file or socket | Intermediate | fuser /var/run/docker.sock | |
fuser -k /pathKill processes using a specific file/port | Expert | fuser -k 8080/tcp | |
fuser -v /pathVerbose mode showing process details | Intermediate | fuser -v /var/log/nginx/access.log |
FAQ
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.