How to search the logs for a problem¶
A service or scheduled job failed, and you need to find what it logged.
This guide narrows the system log down to the messages that matter: by time, by the program that wrote them, by priority and by text.
The example is a job called nightly-backup that failed; replace the name and the search text with your own.
Before you begin¶
- You need a shell with
sudoon the machine. Unprivileged users see only part of the log. - Know roughly when the problem happened, and which service or program was involved, if you can.
- Debian, Ubuntu, the RHEL family and Arch keep their logs in the systemd journal, which you read with
journalctl. Gentoo with OpenRC has no journal: a syslog daemon writes text files under/var/log, which you search withgrep. Gentoo leaves the choice of daemon to the administrator; this guide usessysklogd, as the lab does. With another daemon, the file names differ: check its configuration.
Throughout this guide, replace these placeholders with your own values:
| Placeholder | Meaning | Example |
|---|---|---|
<UNIT> |
The systemd unit or program name to search for | nightly-backup |
<TEXT> |
A word or phrase from the error | No space left |
Steps¶
-
Look at everything the service logged recently.
$ sudo journalctl -u <UNIT> --since "2 hours ago" --no-pager Nov 07 13:40:02 lab systemd[1]: Started nightly-backup.service - Nightly backup. Nov 07 13:40:02 lab nightly-backup[1712]: starting backup of /srv/data Nov 07 13:40:02 lab nightly-backup[1712]: cannot write /srv/backup/data.tar: No space left on device Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Main process exited, code=exited, status=1/FAILURE Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Failed with result 'exit-code'.$ sudo journalctl -u <UNIT> --since "2 hours ago" --no-pager Nov 07 13:40:02 lab systemd[1]: Started nightly-backup.service - Nightly backup. Nov 07 13:40:02 lab nightly-backup[1712]: starting backup of /srv/data Nov 07 13:40:02 lab nightly-backup[1712]: cannot write /srv/backup/data.tar: No space left on device Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Main process exited, code=exited, status=1/FAILURE Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Failed with result 'exit-code'.$ sudo journalctl -u <UNIT> --since "2 hours ago" --no-pager Nov 07 13:40:02 lab systemd[1]: Started nightly-backup.service - Nightly backup. Nov 07 13:40:02 lab nightly-backup[1712]: starting backup of /srv/data Nov 07 13:40:02 lab nightly-backup[1712]: cannot write /srv/backup/data.tar: No space left on device Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Main process exited, code=exited, status=1/FAILURE Nov 07 13:40:02 lab systemd[1]: nightly-backup.service: Failed with result 'exit-code'.With sysklogd's default
/etc/syslog.conf,/var/log/syslogreceives every message except authentication messages. Search it for the program's name:$ sudo grep '<UNIT>' /var/log/syslog Nov 7 13:40:02 lab nightly-backup: starting backup of /srv/data Nov 7 13:40:02 lab nightly-backup: cannot write /srv/backup/data.tar: No space left on deviceOpenRC doesn't log a service's exit status the way systemd does; check the service's state with
rc-service <UNIT> statusorrc-status --crashed.-uselects the messages of one unit, including systemd's own messages about starting and stopping it. If the program isn't a systemd unit, for example a script run from cron, select it by the name it logs under with-t(the syslog identifier) instead:sudo journalctl -t <UNIT>.Note
If
journalctlprints-- No entries --for a time before the last reboot, the journal on that machine may be kept only in memory. Check withsudo journalctl --list-boots; if only one boot is listed, see How to keep logs across reboots. -
If you don't know which service is involved, list only the errors of the current boot.
-p errshows messages of priorityerrand more severe (crit,alert,emerg). Use-p warningto include warnings, and-b -1instead of-bto look at the previous boot. -
Search for the error text across the whole log, to see when it first appeared and whether other programs report it too.
-gtakes a regular expression, and matches without regard to case unless the pattern contains an upper-case letter. -
Read what else happened on the system around that time. Errors in one program often follow a problem elsewhere, such as a full disk, a network outage or the kernel killing a process. Take the time of the error from the previous steps and read the messages from every source around it:
The example shows the last two hours; for a real investigation, give the exact window around the error, such as
--since "2026-11-07 13:35" --until "2026-11-07 13:45".-o short-isoprints full ISO 8601 timestamps, which are easier to compare than the default format. To see only kernel messages, add-kon the systemd families.
Verify¶
Check that you're searching the right place, by writing a test message of your own and finding it again.
logger sends a message to the system log with the tag and priority you give it:
If the test message appears but the messages you're looking for don't, the program logs somewhere else: look for its own files under /var/log/<UNIT>/ or in its configuration.
Troubleshooting¶
Hint: You are currently not seeing messages from other users and the system.- You ran
journalctlwithoutsudo, as a user who isn't in thesystemd-journaloradmgroup, so only your own messages are shown. Run it withsudo, or add the user to one of those groups. -- No entries --for a unit you know exists- Check the unit's exact name with
systemctl list-units --all '<UNIT>*':-uneeds the full name, although the.servicesuffix can be left out. Also check the time window:--sincewithout a date means today. grep: /var/log/syslog: No such file or directory- No syslog daemon writes that file. On Debian 13 and Arch no syslog daemon is installed by default, so use
journalctl. On the RHEL family,rsyslogwrites/var/log/messagesinstead. On Gentoo, check that the syslog daemon is running withrc-service sysklogd status. - Messages from before the last reboot are missing
- The journal is kept only in memory (in
/run/log/journal) on this machine. See How to keep logs across reboots.
Related¶
- Reference: journalctl, Syslog facilities and priorities, Diagnostic commands
- Explanation: Linux logging architecture, A troubleshooting method
- How-to: How to keep logs across reboots, How to rotate an application's logs, How to forward logs to a remote syslog server