Where to start First steps track · 15 stages
Linux Labs

lsof — open files and ports of processes

cheat sheet · Linux https://lab.dimsanych.ru/en/wiki/lsof/

Cheat sheet

  • sudo lsof -i :5432 -nP who's on this port
  • sudo lsof +D /dir who holds a directory
  • sudo lsof +L1 deleted but open files
  • sudo lsof -p 1234 | wc -l how 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 ...))
Loading…