Last Updated: February 25, 2016
·
1.874K
· kevinsuttle

A function to find and kill processes running on a certain port

searchAndDestroy() {
  lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
  echo "Port" $1 "found and killed."
}

Usage: searchAndDestroy 3000

Note: this was my first crack at this. Help me improve it! https://github.com/kevinSuttle/dotfiles/pulls

2 Responses
Add your response

Useless use of grep, awk does the same thing :)

lsof -i TCP:$1 | awk '/LISTEN/{print $2}' | xargs kill -9

over 1 year ago ·

Thanks @kevinsuttle & @sejeff!

over 1 year ago ·