Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Created August 14, 2024 11:40
Show Gist options
  • Select an option

  • Save AlexHedley/fb03b3c6553c215a70a65adbfb80cf43 to your computer and use it in GitHub Desktop.

Select an option

Save AlexHedley/fb03b3c6553c215a70a65adbfb80cf43 to your computer and use it in GitHub Desktop.
Command Ports

This absurd "one-liner" will show you the name of the command running on each port on MacOS, which is something I need to do constantly so leaving it here:

sudo lsof -iTCP -sTCP:LISTEN -n -P | awk 'NR>1 {print $9, $1, $2}' | sed 's/.*://' | while read port process pid; do echo "Port $port: $(ps -p $pid -o command= | sed 's/^-//') (PID: $pid)"; done | sort -n
@AlexHedley
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment