List listening TCP ports and their processes
Build a paste-ready command, then review its compatibility and effects before running it.
lsof -iTCP -sTCP:LISTEN -n -Pread-onlyno known side effects Compatibility
Linux + macOSVerified for Linux, macOS using posix, bash, zsh syntax.
Operational knowledgereview due 2027-01-19
Requirementslsoflsof must be installed and available on PATH.
Version supportlsof Current supported releasesVerified for linux, macos using posix, bash, zsh syntax; consult compatibility notes for platform-specific differences.
Expected signalsCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMERepresentative successful output; values vary with the selected target and system state.
Known errorslsof: command not foundlsof is missing or is not available on PATH.
Verifylsof -iTCP -sTCP:LISTEN -n -PThe output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01lsofOpen-file inspectorLists files and sockets opened by processes.
02-iTCPTCP socketsRestricts results to TCP network sockets.
03-sTCP:LISTENListening stateKeeps only TCP sockets waiting for incoming connections.
04-nNumeric hostsSkips hostname resolution for faster output.
05-PNumeric portsShows port numbers instead of service names.
Example input
lsof -iTCP -sTCP:LISTEN -n -P
Example output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 7310 app 21u IPv4 87341 0t0 TCP *:3000 (LISTEN)
postgres 1842 db 7u IPv4 61982 0t0 TCP 127.0.0.1:5432 (LISTEN)
Illustrative output — exact values vary by system and data.
Runbooks
Official sources