Skip to content

Instantly share code, notes, and snippets.

@DineshSolanki
Created May 23, 2021 11:21
Show Gist options
  • Save DineshSolanki/022b4e2f3852e804dfaa5b6bdf47d6a5 to your computer and use it in GitHub Desktop.
Save DineshSolanki/022b4e2f3852e804dfaa5b6bdf47d6a5 to your computer and use it in GitHub Desktop.
Kill applications that uses given ports
#!/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