DEV Community

Yogeshwaran Tech Tools
Yogeshwaran Tech Tools

Posted on

12 Linux commands I run first when a server misbehaves

When a server is slow or a service is down, a fixed routine beats guessing. These are the twelve commands I run first, in order, and what to look for.

1. Is the machine overloaded?

uptime
Enter fullscreen mode Exit fullscreen mode

The three load averages (1, 5, 15 minutes) should be below your CPU count. Compare with nproc.

2. Who is using CPU and memory?

top -o %CPU        # or: htop
ps aux --sort=-%mem | head
Enter fullscreen mode Exit fullscreen mode

Look for one process dominating, or many copies of the same process.

3. Is memory exhausted?

free -h
dmesg -T | grep -i -E 'out of memory|oom' | tail
Enter fullscreen mode Exit fullscreen mode

If available is near zero or the kernel killed processes, you have a memory problem, not a CPU one.

4. Is the disk full?

df -h
df -i              # inodes can run out even when space is free
du -xh /var --max-depth=1 | sort -h | tail
Enter fullscreen mode Exit fullscreen mode

A full /var (logs) is the most common cause of mysterious failures.

5. Is the disk slow?

iostat -x 1 3      # from the sysstat package
Enter fullscreen mode Exit fullscreen mode

High %util and await mean the disk is the bottleneck.

6. What failed recently?

systemctl --failed
journalctl -p err -b --no-pager | tail -50
Enter fullscreen mode Exit fullscreen mode

7. Is the service itself healthy?

systemctl status myapp
journalctl -u myapp -n 100 --no-pager
Enter fullscreen mode Exit fullscreen mode

8. Is anything listening where it should?

ss -tulpn          # listening sockets and the owning process
Enter fullscreen mode Exit fullscreen mode

9. Can the network reach the world?

ping -c 3 1.1.1.1
curl -sI https://example.com | head -5
dig +short example.com
Enter fullscreen mode Exit fullscreen mode

If IP works but names do not, it is DNS.

10. How many connections are open?

ss -s
ss -tan state established | wc -l
Enter fullscreen mode Exit fullscreen mode

A sudden spike can mean traffic, a leak or an attack.

11. Did a recent change cause it?

last -n 10                 # recent logins
find /etc -mmin -60 -type f 2>/dev/null   # config changed in the last hour
Enter fullscreen mode Exit fullscreen mode

12. Is the clock right?

timedatectl
Enter fullscreen mode Exit fullscreen mode

Wrong time breaks TLS, tokens and log correlation.

Habit worth building

Write down the output of each step as you go. Most incidents are solved by step 4 or 6, and the notes make the post-mortem easy.

For quick offline helpers while debugging (JSON, Base64, URL encoding), I keep a browser-only toolbox here: https://luxury-malabi-8a7447.netlify.app/toolbox.html

Written by Yogeshwaran Tech Tools. Corrections welcome.

Top comments (0)