Created
May 23, 2021 11:21
-
-
Save DineshSolanki/022b4e2f3852e804dfaa5b6bdf47d6a5 to your computer and use it in GitHub Desktop.
Kill applications that uses given ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo "No ports provided" | |
exit 1 | |
fi | |
for var in "$@" | |
do | |
sudo kill -9 $(sudo lsof -t -i:${var}) | |
echo "Process using port ${var} was killed" | |
done | |
echo "" | |
echo "All given ports have been freed." | |
#usage - killport.sh port1 port2 and so on... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment