How to Find Process by Port on Linux Quickly
To find the process using a specific port on Linux, use the command
lsof -i :PORT or netstat -tulpn | grep PORT. Replace PORT with the port number you want to check. These commands show the process ID and name listening on that port.Syntax
The main commands to find a process by port are:
lsof -i :PORT: Lists open files related to the specified port.netstat -tulpn | grep PORT: Shows network connections with process info filtered by port.
Replace PORT with the actual port number you want to check.
bash
lsof -i :PORT netstat -tulpn | grep PORT
Example
This example finds the process using port 8080. It shows the process ID and name listening on that port.
bash
lsof -i :8080Output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python3 1234 user 10u IPv4 12345 0t0 TCP *:http-alt (LISTEN)
Common Pitfalls
Common mistakes include:
- Not running commands with
sudowhen required, which may hide some processes. - Using the wrong port number or forgetting to replace
PORTin the command. - Using
netstaton systems where it is deprecated; preferssorlsof.
Always check if you have the right permissions and the correct port number.
bash
netstat -tulpn | grep 80 # Might show no output if not run with sudo sudo netstat -tulpn | grep 80 # Correct way to see processes on port 80
Quick Reference
| Command | Description |
|---|---|
| lsof -i :PORT | List process using the specified port |
| netstat -tulpn | grep PORT | Show listening processes on the port (may need sudo) |
| ss -tulpn | grep PORT | Modern alternative to netstat to find process by port |
Key Takeaways
Use
lsof -i :PORT to quickly find the process using a port.Run commands with
sudo to see all processes if needed.Replace
PORT with the actual port number you want to check.On newer systems, prefer
ss over netstat for network info.Check permissions and command syntax carefully to avoid missing results.