Back to Snippets

System Administration

Useful commands for managing Linux systems, checking processes, and monitoring resources.

Caution:Commands involving process termination (kill) or system logs should be used with care. Always verify PIDs and file paths before execution.

Active Port & PID Finder

Quickly locate which process (PID) is listening on a specific port. Replace '<PORT>' with the port number you want to check (e.g., 8080).

ss -tulpn | grep :<PORT>

High CPU Usage Process

Identifies the top 5 processes consuming the most CPU in real-time. Use 'kill <PID>' to terminate a stuck process.

ps aux --sort=-%cpu | head -n 6

Log Error Counter (500/404)

Counts how many 500 or 404 errors occurred per day in your web server logs. Useful for tracking daily error trends.

grep -E " 500 | 404 " /path/to/access.log | awk '{print $4}' | cut -d: -f1 | sort | uniq -c

Failed SSH Attempts

Filters and counts failed SSH login attempts from auth.log. Essential for monitoring brute-force attacks.

grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head -n 10