Cheatsheet: Find Listening Ports
Last updated 2026-09-20
Using lsof (Linux and macOS)
Find the process listening on a specific port. Works the same on Linux and macOS.
List all network connections and listening processes, with numeric ports/addresses.
Restrict to TCP sockets that are actually in the LISTEN state.
Print only the PID(s) for a port, useful for scripting (e.g. kill whatever is bound to it).
Using netstat (per-OS differences)
Linux: find the process ID and program name for a specific port with the -p flag.
Linux: list all listening TCP/UDP processes.
macOS/BSD: netstat has no -p flag, so it can confirm the port is listening but not the owning process.
macOS: pair netstat's confirmation with lsof to get the PID, since netstat alone can't show it.
Using ss (Linux)
Find details about a specific port, including the owning process with -p.
List all listening TCP/UDP processes.
Restrict output to listening sockets only (the -l flag).
Filter by destination or source port directly using ss's own port syntax instead of piping to grep.
Using fuser
Find the process using a specific port