A simple Bash script to identify processes using a specified port, retrieve their process IDs (PIDs), and terminate them. This script requires superuser (sudo) permissions to run.
The closeport.sh
script is designed to help system administrators and users easily manage network ports by terminating any processes that are currently using a specified port.
- Takes a port number as an argument.
- Identifies if any processes are using the specified port.
- Retrieves the process IDs (PIDs) of these processes.
- Terminates the processes using the specified port.
- Provides feedback on whether any processes were found and terminated or if the port was unused.
- Bash shell
sudo
privileges
-
Clone the Repository
git clone https://github.com/isaka-james/closeport.git
-
Navigate to the Repository
cd closeport
-
Make the Script Executable
chmod +x closeport.sh
-
Run the Script
sudo ./closeport.sh <port_number>
Replace
<port_number>
with the port number you want to check and close. For example:sudo ./closeport.sh 8080
If the script is run with port 8080
and there is a process using this port, you might see output like:
Process with PID 1234 is using port 8080 and has been terminated.
If no process is found using the specified port:
No process is using port 8080.
sudo chmod +x closeport.sh && sudo mv closeport closeport && sudo mv closeport /usr/bin && echo "Installed successfully!"
So now you can type sudo closeport 8080
to forcefully stop PORT 8080 in your MACHINE.
If you ever feel to uninstall it then type sudo rm -rf /usr/bin/closeport
This project is licensed under the MIT License. See the LICENSE file for details.
Isaka James