Network

The lsof command

Lists the files opened by processes. With -i, it shows which processes use the network and which ports listen.

Syntax

lsof -i [:PUERTO] | lsof archivo

Most useful options

-iOnly network connections
-i :80Only the given port
-p PIDOnly the given process

Copy-ready examples

$ lsof -iOpen network connections

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • It needs sudo to see other users' processes.

Related commands

FAQ

How do I know what occupies a port?

With lsof -i :PORT or ss -ltnp.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course