lsof List open files
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
lsof -i :<port>
lsof -iTCP -sTCP:LISTEN -nP
lsof -p <pid>
lsof -u <user>
lsof <file>
lsof +D <dir>
lsof -t -i :<port>
lsof +L1Concepts
- Selectors -i -p -u -c names
- Matching files every open file
- Output table, PIDs, fields
Find by process
lsof -p <pid>
lsof -p <pid1>,<pid2>
lsof -p ^<pid>
lsof -c <prefix>
lsof -c /<regex>/i
lsof -c ^<prefix>
lsof -g <pgid>
lsof -Rlsof -d cwd -a -p <pid>
lsof -d txt -a -p <pid>
Find by user and file
lsof -u <user>
lsof -u ^<user>
lsof <file>
lsof <mountpoint>
lsof +d <dir>
lsof +D <dir>
lsof -d <fds>
lsof -d ^mem,^txt -p <pid>
lsof -Nlsof -a -u <user> -d ^mem
Network
lsof -ilsof -i :<port>
lsof -i TCP:<port>
lsof -i :<p1>-<p2>
lsof -i :<p1>,<p2>
lsof -i @<host>
lsof -i <4|6>
lsof -iTCP -sTCP:LISTEN
lsof -iTCP -sTCP:ESTABLISHED
lsof -iUDPlsof -i -s TCP:^LISTEN
lsof -nP -ilsof -Ulsof -a -U -c <cmd>
lsof -i -a -p <pid>
Output control
lsof -t <selectors>
lsof -llsof -Hlsof -olsof -slsof -F pcnlsof -wlsof +c 0lsof -r <secs>
lsof +r <secs>
lsof +L1lsof +Llsof -Vlsof -vReading the table
| FD | Meaning |
|---|---|
cwd |
Current directory |
txt |
Program binary |
mem |
Memory-mapped file or library |
rtd |
Root directory |
3u |
Descriptor 3, open read and write |
4r / 5w |
Read-only / write-only |
DEL |
Mapped file deleted |
| TYPE | Meaning |
|---|---|
REG |
Regular file |
DIR |
Directory |
CHR |
Character device |
FIFO / PIPE |
Pipe |
unix |
Unix domain socket |
IPv4 / IPv6 |
Network socket |
Recipes
# find the PID, then stop itlsof -t -i :8080kill $(lsof -t -i :8080)
sudo lsof -iTCP -sTCP:LISTEN -nP# only one command (nginx here)sudo lsof -nP -i -a -c nginx
sudo lsof +L1 | grep -i deleted# Linux only: empties the file under a live process, so be suresudo truncate -s 0 /proc/<pid>/fd/<fd>
lsof -nP -i -a -p <pid> -r 2# unmount blocked?lsof /mnt/usb



