Skip to content

Instantly share code, notes, and snippets.

@cmj
Created December 27, 2025 08:50
Show Gist options
  • Select an option

  • Save cmj/2bfa8f7a71bbf32041c4e07586f7fcbe to your computer and use it in GitHub Desktop.

Select an option

Save cmj/2bfa8f7a71bbf32041c4e07586f7fcbe to your computer and use it in GitHub Desktop.
Show working directory of process listening on port number
#!/bin/bash
if [[ -z $1 ]]; then echo "$0 <port> # show cwd and process listening on port"; exit 1; fi
sudo lsof -w -a -p $(lsof -iTCP:$1 -sTCP:LISTEN | awk 'NR>1 {print $2}') -d cwd 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment