Home / CodeShell / Shell / How to Check Port Availability and Kill Processes in Linux

How to Check Port Availability and Kill Processes in Linux

How to Check Port Availability and Kill Processes in Linux
  • Category Shell
  • Type Command
  • Platform Linux
  • Language Bash
  • Price Free
  • Copy 1 658
  • Comments 0
Go to Code
How to Check Port Availability and Kill Processes in Linux

How to Check Port Availability and Kill Processes in Linux

Copy this Bash snippet on Clayi Code — one click, no account required. Free command snippets with syntax highlighting and instant copy — built for developers and sysadmins.

What it does and when to use

A ready-to-run terminal command you can paste into your shell and execute. Handy for file search, disk usage, permissions, networking, process management, and everyday admin work.

How to copy from Clayi Code

Scroll to the code box, click Copy, and paste into your terminal or SSH session.

Run it on the right shell

Do not paste Bash into CMD, or PowerShell into Bash. Use the shell that matches your system.

Command safety

Read the full command before running. Some one-liners can change or delete data — test on non-production systems when unsure. Watch quoting, paths, and sudo usage; use bash -n or ShellCheck on longer scripts.

Shell reference

Category: Shell. Language: Bash. Platform: Linux. Format: Command.

Popularity
0%
  • Votes: 159
  • Comments: 0

How to Check Port Availability and Kill Processes in Linux

#!/usr/bin/env bash
# Check if a specific port is in use and forcefully kill the process
# Usage: ./kill-port.sh [port_number]

PORT="${1:-8080}"
PID=$(lsof -t -i:"$PORT")

if [ -z "$PID" ]; then
    echo "Port $PORT is free."
else
    echo "Killing process $PID on port $PORT..."
    kill -9 "$PID"
fi
Free snippet — copy & paste!
Copy this snippet for free on Clayi Code. One click — no account required.

Similar Snippets

Populer Snippets

There are no comments yet :(

How to Check Port Availability and Kill Processes in Linux
Tell us what you think about "How to Check Port Availability and Kill Processes in Linux"
Information
Users of Guests are not allowed to comment this publication.