Back to Snippets
7 snippets

System Administration

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

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).

bash
ss -tulpn | grep :<PORT>

High CPU Usage Processes

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

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

High Memory Usage Processes

Lists top 10 processes sorted by memory usage. Useful when diagnosing memory leaks or OOM (Out of Memory) conditions.

bash
ps aux --sort=-%mem | head -n 11 | awk '{printf "%-10s %-6s %-6s %s\n", $1, $2, $4, $11}'

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.

bash
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, sorted by frequency. Essential for monitoring brute-force attacks.

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

Who is Logged In Right Now

Shows all users currently logged into the system, their terminal, login time, and originating IP. Good for security auditing.

bash
who -a
# or for more detail with idle time:
w

Systemd Service Quick Check

Check the status, enable at boot, restart, or tail logs for any systemd service. Replace 'nginx' with your target service name.

bash
# Check status
systemctl status nginx

# Enable on boot
systemctl enable nginx

# Restart service
systemctl restart nginx

# Tail logs (last 50 lines, follow)
journalctl -u nginx -n 50 -f