All articles
165 articles · updated weekly See our Tools
All articles
Tutorials

Essential Linux Commands for Servers: A Diagnostic Guide

systemctl, journalctl, top, df, ss and grep: the commands to find out in minutes why the service died, the disk filled up or the server got slow.

Essential Linux Commands for Servers: A Diagnostic Guide
COVER · Tutorials

You open a terminal, connect to a production server, and get this: Active: failed (Result: exit-code). The service is down, and nobody knows since when or why. Or a teammate hands you a "it's slow" that explains nothing, and you need to find out what's eating CPU, memory or disk without a dashboard installed.

That's when the administration commands matter. Not the navigation ones, which the Linux for beginners post already covers, but the ones you use to understand what's happening on a real server, right now. This post is a diagnostic runbook: each section is short and points to the deep dive when there is one. I ran every command in a Debian 12 container with systemd 252 as PID 1, an nginx up and a test service rigged to fail.

The summary, before the details:

Symptom First command What to look at
Service is down systemctl --failed and systemctl status app Active: and the last log lines
Don't know why it died journalctl -u app -n 100 --no-pager the first error message, not the last
"It's slow" uptime, free -h, top -b -n 1 -o %CPU load average vs cores, available memory
Disk full df -h and df -i Use% and IUse% close to 100%
Port doesn't answer ss -tulnp whether the process is listening, and on which address
Error buried in a log grep -i -C 3 "error" file.log the context around the line

systemctl: is the service up?

systemctl is the interface to systemd, the default init on Debian, Ubuntu, RHEL, Fedora and their derivatives. Start with the list of what failed:

$ systemctl --failed
  UNIT          LOAD   ACTIVE SUB    DESCRIPTION
● myapp.service loaded failed failed app que falha

Then the service status, which already includes the last log lines and often answers the question on its own:

$ systemctl status myapp --no-pager
× myapp.service - app que falha
     Active: failed (Result: exit-code) since Mon 2026-11-09 11:29:24 UTC; 8s ago
   Main PID: 47 (code=exited, status=3)
Nov 09 11:29:24 a01c07a3d3b8 sh[47]: ERROR: conexao recusada com o banco
Nov 09 11:29:24 a01c07a3d3b8 systemd[1]: myapp.service: Failed with result 'exit-code'.

(output trimmed). The everyday verbs are start, stop, restart, reload (re-reads the config without stopping, when the service supports it), enable and disable (start at boot or not). How to write a unit for your own service is in the post about creating systemd services.

journalctl: what happened before it died

journalctl reads the systemd journal, indexed by service, boot and priority:

journalctl -u myapp -n 100 --no-pager   # last 100 lines, no pager
journalctl -u myapp -f                  # follow live, like tail -f
journalctl -u myapp -b                  # current boot only
journalctl -u myapp --since "2026-11-09 10:00" --until "2026-11-09 11:00"

Two catches I hit in the test. First: -p err doesn't catch everything that looks like an error. My service wrote ERROR: conexao recusada com o banco to stderr, and journalctl -u myapp -p err came back empty. -o verbose showed why: the line was stored with PRIORITY=6 (info), because systemd logs stdout and stderr at the SyslogLevel= level, which defaults to info, per the systemd.exec manual. Only applications that send a priority (through syslog/journald, or with prefixes like <3> on the line) show up in the filter. For application logs, filter by text with grep.

Second: -b -1 (previous boot) only works with a persistent journal. With Storage=auto (the value shipped commented out in Debian 12's journald.conf), journald.conf only writes to disk if the /var/log/journal directory exists; without it, the journal lives in /run, which is wiped on reboot, and the command answers No such boot ID in journal. journalctl --list-boots shows how many boots are stored; if there's only one, yesterday's crash log is gone.

uptime, free, top and ps: why is the server slow?

Before hunting processes, look at the load:

$ uptime
 11:29:50 up 10 days, 15:47,  0 user,  load average: 2.80, 2.49, 2.25
$ nproc
20
$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       1.8Gi        11Gi        29Mi       2.6Gi        13Gi

Load average is the number of jobs running or waiting on disk I/O, averaged over 1, 5 and 15 minutes, according to the /proc/loadavg manual. Compare it with the core count from nproc: 2.8 on 20 cores is headroom; 30 on 4 cores is a queue. For memory, read the available column, not free: Linux uses free memory as disk cache and hands it back when something needs it.

To find the process, I use top in batch mode:

top -b -n 1 -o %CPU | head -15

ps aux --sort=-%cpu shows up in every tutorial, but there's a catch: ps's %CPU is CPU time divided by the process's lifetime, an average since it started, as the ps manual explains. A process that got stuck at 100% a minute ago after a week idle shows up low. For "who is burning CPU right now", use top. ps is still great for the rest:

ps -eo pid,user,stat,%cpu,%mem,cmd --sort=-%mem | head   # who holds the most memory
ps auxf                                                  # tree: who spawned whom
pgrep -a nginx                                           # PIDs and command line

In the STAT column: R running or queued, S sleeping (normal), D uninterruptible sleep (usually waiting on disk; lots of D means saturated I/O) and Z zombie (the child exited and the parent never collected its status with wait()).

df and du: is the disk full?

df -h      # space per filesystem
df -hT     # with the type (ext4, xfs, overlay)
df -i      # inodes: you can "fill" a disk with space left
du -h /var --max-depth=2 2>/dev/null | sort -rh | head -20

df -i catches the less obvious case: millions of small files (PHP sessions, queues, cache) exhaust the inodes and nothing new can be created, even with gigabytes free. The full walkthrough is in investigating a full disk, and hunting the heaviest files in finding large files on Linux.

ss: what's listening and who's connected

ss replaced netstat; the netstat manual itself says it is "mostly obsolete" and names ss as the replacement.

ss -tuln                  # TCP/UDP ports in listening state (LISTEN only)
ss -tulnp                 # same, with the owning process (needs root to see all)
ss -tn state established  # connections established right now
ss -tlnp 'sport = :80'    # who listens on port 80
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn   # connections per state

-l is the flag people mix up: it shows only listening sockets. In the test, with a connection open to port 8080, ss -tuln listed only the three LISTEN lines; the ESTAB connection only appeared in ss -tan. If the app listens on 127.0.0.1:8080 and you test from outside, the Local Address already tells you why it doesn't answer. In the last command, NR>1 drops the header, otherwise "State" gets counted. Thousands of CLOSE_WAIT usually point to an app that doesn't close connections; lots of TIME_WAIT, to very short connections without keep-alive. To review which ports each service uses, the post about network ports has the list.

grep: pulling signal out of noise

grep -i "error" /var/log/app/app.log                # case-insensitive
grep -C 3 "Connection refused" /var/log/app/app.log # 3 lines of context
grep -v "GET /health" /var/log/nginx/access.log     # everything but the health check
grep -rl "CRITICAL" /var/log/                       # file names only
journalctl -u postgresql --no-pager | grep -iE "fatal|error|could not"

In the nginx access log, a regular expression pulls the most frequent IPs, and awk counts HTTP statuses (grep -c "404" would also count any line with "404" in the size or the URL):

grep -oP '^\d+\.\d+\.\d+\.\d+' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c

When the regex gets more involved than that, I test it first in a regex tester against a few real log lines, so I don't find out mid-incident that the pattern doesn't match.

The full runbook in two minutes

New deploy, service responding slowly. In order:

systemctl status myapp --no-pager                     # 1. is it up?
journalctl -u myapp -n 50 --no-pager | grep -iE "error|warn|fatal"   # 2. recent errors?
uptime && free -h                                     # 3. load and memory
top -b -n 1 -o %CPU | head -15                        # 4. who is using CPU now
df -h && df -i                                        # 5. disk and inodes
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c      # 6. connections piling up?

Six steps, two minutes. Most of the time one of them points at the cause and the rest becomes confirmation.

Frequently asked questions

What's the difference between systemctl restart and systemctl reload?

restart stops the service and starts it again, with a brief outage. reload asks the process to re-read its configuration without exiting, but it only works if the unit defines ExecReload=. nginx does (in the test, status logged Reloaded nginx.service); PostgreSQL also reloads most of its settings this way. If you're not sure, systemctl cat service shows the unit.

How do I see the logs of a service that died before a reboot?

journalctl -u service-name -b -1, which shows the previous boot. It requires a persistent journal: check with journalctl --list-boots. If only the current boot appears, create /var/log/journal or set Storage=persistent in journald.conf for next time.

Does ss fully replace netstat?

For diagnostics, yes. netstat comes from the net-tools package, which many minimal installs don't even ship, and its own manual calls it mostly obsolete. The basic flags are similar (ss -tuln does what netstat -tuln did), and ss can also filter by state and port.

What permissions do web server files need?

In general, directories the web server's group can traverse and files it can only read. The numbers are in Linux permissions 755, 775 and 644, and the difference between chmod, chown and umask in chmod, chown and umask. To build the octal without mental math, the chmod calculator shows octal and symbolic side by side and warns when a combination is insecure.

Start at the status, end at the cause

The difference between fixing it in two minutes and poking at it for an hour is knowing which command runs first. systemctl status tells you if the service is up, journalctl -u tells you what happened, uptime, free and top tell you if it's load, df tells you if the disk filled up, and ss tells you if the port is listening. Remember the two traps: ps's %CPU is a lifetime average, and the journal's -p err doesn't see your app's stderr. If the server itself is still an open choice, the post on VPS, VPC and dedicated servers helps decide where to run all this.

RD
Author
Rafael Duarte
Backend developer with a background in fintech and B2B SaaS — worked on teams that scaled APIs from zero to millions of requests. Carries enough production scars to hold strong opinions on tools, patterns and architecture decisions. Not an academic: he read the UUID RFC when he had to choose between v4 and v7 for a write-heavy table.
View profile