cmdxray / commands / lsof

What does lsof do?

list open files (and the processes that hold them open).

▸ Explain your own lsof command →

lsof examples, explained

$ lsof -i :8080

  • lsoflist open files (and the processes that hold them open)
  • -ilist network files — optionally filtered, e.g. -i :8080, -i tcp:80
  • :8080value for -i

$ lsof -p 1234

  • lsoflist open files (and the processes that hold them open)
  • -prestrict to the given process ID(s)
  • 1234value for -p

$ lsof -nP -i tcp

  • lsoflist open files (and the processes that hold them open)
  • -ndon't resolve host names — numeric addresses (faster)
  • -Pdon't resolve port names — numeric ports (faster)
  • -ilist network files — optionally filtered, e.g. -i :8080, -i tcp:80
  • tcpvalue for -i

lsof flags & options

-ilist network files — optionally filtered, e.g. -i :8080, -i tcp:80
-prestrict to the given process ID(s)
-urestrict to files opened by the given user(s)
-crestrict to processes whose name begins with this string
-ndon't resolve host names — numeric addresses (faster)
-Pdon't resolve port names — numeric ports (faster)
-tterse output — print only process IDs (handy for scripting)
-aAND the selection filters together instead of OR-ing them

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.