Skip to content

Instantly share code, notes, and snippets.

@nikolareljin
Last active July 31, 2019 21:03
Show Gist options
  • Save nikolareljin/aae6d93e144cb28b7d6cbe5b8abef8d1 to your computer and use it in GitHub Desktop.
Save nikolareljin/aae6d93e144cb28b7d6cbe5b8abef8d1 to your computer and use it in GitHub Desktop.
Kill all apps running on certain port
#!/usr/bin/env bash
# -------------------------------------------------
# Kills all apps running on given port
# Use:
# kill_apps_on_port.sh <port>
# -------------------------------------------------
PORT_NUMBER=$1
echo "Kill all applications running on port ${PORT_NUMBER}"
lsof -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | sudo xargs kill
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment