Useful Linux Commands

This page is a reference for useful command-line tools and one-liners for server management, grouped by category.


lsof -i tcp:8080

Finds the process ID (PID) that is holding onto a specific network port.

Find Process by Port
lsof -i tcp:8080

netstat -plunt

Shows which programs are actively listening on TCP and UDP ports.

Show Listening Ports
netstat -plunt

iptables -A INPUT -s 1.2.3.4/32 -j DROP

Bans a given IP address from accessing your server using the firewall.

Ban an IP Address
iptables -A INPUT -s 1.2.3.4/32 -j DROP

fuser -k filename

Kills a process that is currently locking a file.

Kill Process Locking a File
fuser -k filename

python -m SimpleHTTPServer

Starts a simple web server in the current directory on port 8000.

Start Simple Web Server
python -m SimpleHTTPServer