Skip to content

Instantly share code, notes, and snippets.

@ERPedersen
Last active October 18, 2019 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ERPedersen/21b3e3e9f9efc8dc0eb2150547cbc23a to your computer and use it in GitHub Desktop.
Save ERPedersen/21b3e3e9f9efc8dc0eb2150547cbc23a to your computer and use it in GitHub Desktop.
Free blocked port
# Frees up the provided port by killing whatever process is blocking it.
#
# Example:
# freeport 8080
function freeport () {
local result=$(lsof -i :$1 | grep node | awk '{print $2}')
if [[ ! -z $result ]]; then
kill $result
echo "Process $result successfully killed"
echo "Port $1 is now free"
else
echo "Port $1 is already free"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment