Skip to content

Instantly share code, notes, and snippets.

@mig82
Last active June 28, 2022 18:04
Show Gist options
  • Save mig82/2b36d037095feb84d0b0e663559294fe to your computer and use it in GitHub Desktop.
Save mig82/2b36d037095feb84d0b0e663559294fe to your computer and use it in GitHub Desktop.
findbyport and killbyport
findbyport() {
# lsof -i | grep ":$@" | awk '{print "Program: " $1 "\t" "PID: "$2 "\t" "User: " $3 "\t" "Address: "$9 "\t" "Action: " $10 }'
lsof -i ":$@" | grep ":$@" | awk '{print $2}'
}
killbyport() {
kill $(findbyport $@)
}
portsinuse() {
lsof -nP | grep "IPv" | while read line; do echo $line | awk '{print "Program: " $1 "\n" "PID: "$2 "\n" "User: " $3 "\n" "Address: "$9 "\n" "Action: " $10}'; echo; done;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment