Reading Logs With journalctl in Linux: A Practical Guide
Something goes wrong on a Linux server.
Nginx refuses to start.
SSH suddenly rejects connections.
A disk fails to mount.
A service crashes five minutes after boot.
The quickest route to the answer is often not reinstalling anything or randomly changing configuration.
It is:
read the logs.
On most modern Linux distributions that use systemd, one of the most important tools for doing that is:
journalctl
journalctl reads records collected by systemd-journald, including output from system services and other system components.
The problem is that simply typing:
journalctl
can give you thousands or millions of entries.
The real skill is knowing how to narrow the journal until the relevant failure becomes obvious.
Start With the Service, Not the Entire Journal
Suppose Nginx has failed.
Do not begin with:
sudo journalctl
and scroll through the whole operating system.
Start with:
sudo systemctl status nginx
systemctl status shows the current or most recent state of the unit and includes a small selection of recent journal messages. systemd's own documentation recommends journalctl --unit= when you need the fuller log history for that service.
Then run:
sudo journalctl -u nginx
or, where the unit has the full name:
sudo journalctl -u nginx.service
Now you are looking at the relevant service rather than:
SSH
kernel messages
cron
networking
unrelated applications
all mixed together.
That is usually the best starting point.
Show the Latest Messages First
By default, journalctl displays entries chronologically from oldest to newest.
For troubleshooting, the latest entries are often more useful.
Use:
sudo journalctl -u nginx -r
-r reverses the output so newest entries appear first.
Or show only the last 50 entries:
sudo journalctl -u nginx -n 50
You can combine them:
sudo journalctl -u nginx -n 50 --no-pager
--no-pager is particularly useful when:
copying output
scripting
working in a terminal where less is inconvenient
because journalctl normally sends long output through a pager.
Logs From the Current Boot
One of the most useful filters is:
sudo journalctl -b
This shows messages from the current boot.
That is ideal when the problem occurred after restarting the server.
For one service:
sudo journalctl -u nginx -b
Now you are asking:
What has Nginx logged since this machine started?
instead of looking through weeks of history.
Previous Boot
Suppose the server crashed overnight and was restarted.
The interesting evidence may belong to the boot before the current one.
Use:
sudo journalctl -b -1
For two boots ago:
sudo journalctl -b -2
You can list known boots with:
sudo journalctl --list-boots
Then investigate a specific one.
This is extremely useful for:
unexpected shutdowns
kernel crashes
services that fail during boot
hardware issues that disappear after restarting
Current journalctl documentation also gives journalctl -k -b -1 as an example for viewing kernel logs from the previous boot.
Filter by Time
If somebody tells you:
“The website stopped working at about 14:20.”
do not read a whole day's logs.
Use:
sudo journalctl --since "14:00" --until "14:40"
Or:
sudo journalctl --since "2026-08-20 14:00:00"
You can also use convenient relative expressions such as:
sudo journalctl --since "1 hour ago"
or:
sudo journalctl --since yesterday
For a specific service:
sudo journalctl -u nginx \
--since "14:00" \
--until "14:40"
This is often dramatically more useful than searching an entire log history.
Follow Logs Live
To watch new events as they arrive:
sudo journalctl -f
This behaves similarly to:
tail -f
but follows the systemd journal.
For one service:
sudo journalctl -u nginx -f
The systemd manual itself uses:
journalctl -f -u apache
as an example of following one service live.
This is extremely useful when troubleshooting a repeatable problem.
For example:
Terminal 1:
sudo journalctl -u nginx -f
Terminal 2:
sudo systemctl restart nginx
Watch Terminal 1.
You see the error at the exact moment it happens.
Filter by Severity
Journal entries can carry severity levels.
Common levels include:
emerg
alert
crit
err
warning
notice
info
debug
Current systemd documentation lists those levels in decreasing severity order.
To show errors and anything more severe:
sudo journalctl -p err
Warnings and above:
sudo journalctl -p warning
For just this boot:
sudo journalctl -b -p warning
For one service:
sudo journalctl -u nginx -p warning
This can remove huge amounts of routine informational output.
But do not assume:
only errors matter.
Sometimes the line immediately before an error explains what caused it.
Use priority filtering to narrow the investigation, then widen the context when necessary.
journalctl -xe — Useful, but Not Magic
A very common troubleshooting command is:
sudo journalctl -xe
It is useful.
But it is often misunderstood.
Broadly:
-e jumps towards the end of the journal
-x adds explanatory catalogue information where available
It does not mean:
“show me exactly what broke.”
If your problem concerns Nginx, this is usually more precise:
sudo journalctl -u nginx -b
than blindly running:
sudo journalctl -xe
Use -xe as a general recent-events view, not as a universal diagnosis command.
Kernel Messages
For kernel-related events:
sudo journalctl -k
For the current boot:
sudo journalctl -k -b
For the previous boot:
sudo journalctl -k -b -1
This is useful when investigating:
disk errors
USB problems
network-driver faults
filesystem problems
hardware detection
kernel warnings
For example:
sudo journalctl -k -b | grep -i nvme
or:
sudo journalctl -k -b | grep -i error
However, do not automatically assume every line containing error describes your actual problem.
Kernel logs can contain historical or non-fatal messages.
Correlate them with the time and symptom.
Troubleshooting a Failed Service
Suppose:
sudo systemctl start nginx
fails.
Use:
sudo systemctl status nginx
Then:
sudo journalctl -u nginx -b -n 100
If necessary, follow live:
sudo journalctl -u nginx -f
Now retry:
sudo systemctl restart nginx
This sequence is much cleaner than immediately editing Nginx configuration at random.
You are using the service itself to tell you why it failed.
Troubleshooting SSH
Depending on the distribution, the unit might be called:
ssh.service
or:
sshd.service
Check:
sudo systemctl status ssh
or:
sudo systemctl status sshd
Then:
sudo journalctl -u sshd -b
or:
sudo journalctl -u ssh -b
If authentication fails repeatedly, this can reveal things such as:
invalid users
rejected keys
configuration errors
service startup failures
Be careful when changing SSH remotely.
Keep an existing session open until you have confirmed that a new connection works.
Troubleshooting a Failed Mount
Suppose a drive listed in /etc/fstab fails during boot.
Start with:
sudo journalctl -b | grep -i mount
Then inspect the generated systemd mount unit where appropriate:
systemctl status mnt-data.mount
For a mount point:
/mnt/data
systemd will commonly represent it as:
mnt-data.mount
This pairs particularly well with:
sudo findmnt --verify
and:
sudo mount -a
Do not reboot repeatedly just to discover whether an fstab edit works.
Test it while you still have access to the system.
Searching for Text
You can pipe output through grep:
sudo journalctl -b | grep -i "failed"
For multiple terms:
sudo journalctl -b | grep -Ei "error|fail|timeout"
But structured journal filters are often better when they exist.
For example:
sudo journalctl -u nginx
is usually better than:
sudo journalctl | grep nginx
because -u understands the unit metadata attached to journal entries.
Current systemd documentation explains that -u/--unit= expands into structured filters covering messages associated with the unit.
System vs User Logs
journalctl can distinguish system services from services running in the current user's systemd instance.
For system entries:
journalctl --system
For the user's journal:
journalctl --user
For a user service:
journalctl --user -u my-service
There is an important caveat: current journalctl documentation notes that --user relies on persistent logging for the relevant user journal.
So if user-service history seems unexpectedly incomplete, journal storage configuration may be part of the explanation.
Do You Need sudo?
Not necessarily for every log.
Users can always access their own private journal information.
Access to the complete system journal is more restricted.
Current systemd documentation notes that root and members of groups such as:
systemd-journal
adm
wheel
depending on distribution configuration, may be able to read wider system journal content.
That is why:
journalctl
may show less than:
sudo journalctl
on some machines.
Do not assume missing log entries mean journald failed to record them.
You may simply lack permission to read them.
Is the Journal Persistent?
This matters after reboot.
systemd can store journal data under:
/run/log/journal/
or:
/var/log/journal/
The former is volatile storage.
The latter provides persistent storage.
Current systemd-journald documentation confirms that /run/log/journal is used when persistent journal storage is unavailable or Storage=volatile is configured, while persistent journals are stored beneath /var/log/journal.
Check:
ls -ld /var/log/journal
You can also inspect:
/etc/systemd/journald.conf
for settings such as:
Storage=
If a server's logs disappear every reboot, verify journal persistence before assuming the historical records should exist.
How Much Space Is the Journal Using?
Run:
sudo journalctl --disk-usage
If journal storage has genuinely become excessive, supported cleanup commands include:
sudo journalctl --vacuum-time=14d
or:
sudo journalctl --vacuum-size=500M
Be careful before deleting logs.
If the system has just experienced:
intrusion
application failure
unexplained reboot
storage problem
the journal may contain evidence you still need.
systemd-journald also automatically removes older archived files according to its configured storage limits.
So do not make:
rm -rf /var/log/journal/*
your routine cleanup strategy.
Use journald's own retention controls.
Persistent Limits Are Better Than Repeated Vacuuming
If the journal repeatedly consumes too much storage, change the retention policy rather than manually vacuuming it every week.
Relevant settings in:
/etc/systemd/journald.conf
can control journal storage and size.
The exact values should reflect:
available disk space
troubleshooting requirements
compliance/retention needs
server purpose
A production server may legitimately need considerably more history than a small disposable test VM.
Exporting Logs for Investigation
If another engineer needs the output:
sudo journalctl -u nginx \
--since "2026-08-20 14:00" \
--until "2026-08-20 15:00" \
--no-pager > nginx-incident.log
Now you have a focused incident log rather than a dump of the complete system journal.
For automation or structured analysis, journalctl also supports JSON output. Current documentation lists several output formats including json, verbose and an export format intended for backup or transfer.
For example:
journalctl -u nginx -o json
This is useful when logs need to be parsed programmatically.
Don't Read Every Log Line Equally
This is the habit that makes journalctl genuinely useful.
Imagine Nginx fails at 14:32.
Do not read:
three months of system logs.
Ask increasingly specific questions:
Which service?
sudo journalctl -u nginx
Which boot?
sudo journalctl -u nginx -b
Which time?
sudo journalctl -u nginx \
--since "14:25" \
--until "14:40"
Which severity?
sudo journalctl -u nginx \
--since "14:25" \
--until "14:40" \
-p warning
Now you may have twenty lines instead of two million.
That is the real power of journalctl.
A Practical Example
Suppose a web server stopped responding at around:
10:17
Check the service:
systemctl status nginx
Then:
sudo journalctl -u nginx \
--since "10:10" \
--until "10:25"
You see:
nginx: [emerg] bind() to 0.0.0.0:443 failed
Now you have a real direction.
Something else may already be using port 443.
Check:
sudo ss -ltnp | grep ':443'
That is considerably better than:
reinstall Nginx and see what happens.
Another Example: Server Rebooted Overnight
Users tell you the Linux server was unreachable overnight.
It is currently running normally.
List boots:
sudo journalctl --list-boots
Check the previous one:
sudo journalctl -b -1 -e
Check kernel messages:
sudo journalctl -k -b -1
Look around the end of that boot for:
storage errors
out-of-memory events
kernel warnings
shutdown activity
Historical logs turn:
“The server went down.”
into an investigation with a timeline.
The Practical journalctl Toolkit
For most day-to-day troubleshooting, you only need a small set of commands:
# Current boot
sudo journalctl -b
# One service
sudo journalctl -u nginx
# One service during this boot
sudo journalctl -u nginx -b
# Recent messages
sudo journalctl -n 100
# Follow live
sudo journalctl -f
# Follow one service
sudo journalctl -u nginx -f
# Since a particular time
sudo journalctl --since "1 hour ago"
# Time range
sudo journalctl --since "14:00" --until "15:00"
# Warnings and worse
sudo journalctl -p warning
# Kernel messages
sudo journalctl -k
# Previous boot
sudo journalctl -b -1
# List boots
sudo journalctl --list-boots
# Journal disk use
sudo journalctl --disk-usage
You do not need to memorise every possible option.
Master those and you can solve a large proportion of everyday Linux log investigations.
The Better Troubleshooting Order
When something fails on a systemd-based Linux machine:
1. Identify the affected service or subsystem.
2. Check:
systemctl status service-name
3. Read its current-boot journal:
sudo journalctl -u service-name -b
4. Narrow the time window.
5. Filter severity if the output remains excessive.
6. Use -f while reproducing the failure.
7. Use -k when hardware/kernel behaviour is involved.
8. Use previous-boot logs if the machine has restarted.
9. Correlate the log message with configuration and system state.
10. Fix the cause rather than merely deleting the log.
The key principle is:
Do not read more logs. Read a smaller, more relevant set of logs.
How Hamilton Group Can Help
Hamilton Group can help businesses diagnose Linux issues involving:
Linux servers
journalctl
systemd
failed services
boot problems
storage
networking
web servers
SSH
application failures
log management
server monitoring
For production systems, logs are particularly valuable because they allow engineers to move from:
“Something stopped working.”
to:
“This component failed, at this time, for this reason.”
Visit hgmssp.com or call 01423 438 953 to discuss Linux server and managed IT support.
0 comments
- Be the first to comment.