lsof — open files and ports of processes
cheat sheet · Linux https://lab.dimsanych.ru/en/wiki/lsof/Cheat sheet
-
sudo lsof -i :5432 -nPwho's on this port -
sudo lsof +D /dirwho holds a directory -
sudo lsof +L1deleted but open files -
sudo lsof -p 1234 | wc -lhow many fds a process has (a leak?) -
sudo kill $(sudo lsof -t -i:8080)kill whoever holds a port
Options
| Option | Meaning |
|---|---|
-i [:port] |
network sockets (optionally by port/host) |
-nP |
skip DNS and port-name resolution (fast, numeric) |
-p PID |
files of a specific process |
-c name |
processes by command name |
-u user |
by user |
+D /dir |
recursively, everything under a directory (what's holding the fs) |
+L1 |
files with fewer than 1 link (deleted but still open) |
-t |
just PIDs (for scripts: kill $(lsof -t ...)) |