Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 6System · Linux

How to read and follow the logs of a service

When a service fails or behaves strangely, the logs tell you why. On modern Linux, most services log to the systemd journal, which you read with journalctl; some apps also write their own files under /var/log. This how-to finds the right logs fast: one service, live, only errors, a time window, the last boot — and the container and Kubernetes versions of the same.

  • 5 Lessons
  • 12 Commands

$ run as a normal user# run as root (or with sudo)

6.1

The quick answer

journalctl -u nginx -n 50 --no-pager
journalctl -u nginx -f
journalctl -u nginx --since "1 hour ago" -p warning
journalctl -xeu nginx

-u = one unit, -n 50 = last 50 lines, -f = follow live, -p warning = warnings and worse, -xe = jump to the end with explanations.

6.2

Step by step

  1. Find the exact unit name:
systemctl list-units --type=service | grep -i nginx
systemctl status nginx --no-pager

systemctl status already shows the last 10 log lines — often enough.

  1. Choose the time window:
journalctl -u nginx --since today
journalctl -u nginx --since "2026-11-17 09:00" --until "2026-11-17 09:30"
journalctl -u nginx -b
journalctl -u nginx -b -1

-b = since this boot; -b -1 = the boot before (great after a crash and reboot — needs a persistent journal, see below).

  1. Only what matters:
journalctl -p err -b
journalctl -u sshd | grep -i "failed password"
journalctl -u myapp -o json-pretty -n 1
journalctl _PID=1432
  1. Apps with their own log files (web servers, databases, Java apps):
ls -lt /var/log | head
tail -F /var/log/nginx/error.log
tail -n 200 /var/log/nginx/access.log | awk '$9 >= 500'
grep -i error /var/log/mariadb/mariadb.log | tail

tail -F (capital F) keeps following when the file is rotated.

  1. Containers and Kubernetes log to stdout:
docker logs --tail 100 -f web
kubectl logs deploy/shop-api --tail 100 -f
kubectl logs shop-api-7c9d8-abcde --previous
  1. Keep logs after a reboot (if -b -1 shows nothing):
mkdir -p /var/log/journal
systemctl restart systemd-journald
journalctl --list-boots | tail -3

6.3

Check that it worked

You see the lines from the time the problem happened, and you can follow new ones live while you test:

journalctl -u nginx -f &
curl -s -o /dev/null http://127.0.0.1/
journalctl --disk-usage

6.4

Common problems

ProblemCauseFix
-- No entries --Wrong unit name or time window, or the app logs to a file.systemctl status for the name; check /var/log/APP/.
Only some lines as a normal userNo permission for system logs.Use sudo, or add the user to systemd-journal (or adm on Ubuntu).
Nothing from before the rebootThe journal is not persistent.Create /var/log/journal and restart journald.
The journal uses many GBNo size limit.journalctl --vacuum-size=500M; set SystemMaxUse= in /etc/systemd/journald.conf.
Container logs fill the diskNo log rotation for containers.Docker daemon.json log max-size/max-file.
The error is not clearShort message only.journalctl -xeu UNIT for context; raise the app's log level for a while.

6.5

Go further

1How do you see the log of a service from the boot before the last crash?

journalctl -u NAME -b -1 — with a persistent journal (/var/log/journal).

2Which command follows a log file even when it is rotated?

All commands in this chapter