Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active April 22, 2018 22:11
Show Gist options
  • Save miguelmota/cd1194976ab6e6fdad54432a9701e72c to your computer and use it in GitHub Desktop.
Save miguelmota/cd1194976ab6e6fdad54432a9701e72c to your computer and use it in GitHub Desktop.
bash script to kill process by name or port (like `fkill` NPM package, but not taking up your entire disk space with node_modules)
# kill process by name or port
# example:
# fkill someapp :8080 node :1111
fkill() {
for i in $@;do export q=$i;if [[ $i == :* ]];then lsof -i$i|sed -n '1!p';
else ps aux|grep -i $i|grep -v grep;fi|awk '{print $2}'|\
xargs -I@ sh -c 'kill -9 @&&printf "X %s->%s\n" $q @';done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment