Where do Linux logs live?
Every image we install runs systemd, which collects messages from the kernel, services and anything printed to stdout by a unit into the journal. Many services also write their own text files under /var/log. Debian and Ubuntu still run rsyslog by default on most installs, which copies journal messages into text files as well. The RHEL family does the same with its own file names.
| What | Debian, Ubuntu | AlmaLinux, Rocky, CentOS Stream |
|---|---|---|
| General system messages | /var/log/syslog | /var/log/messages |
| Logins, sudo, SSH | /var/log/auth.log | /var/log/secure |
| Package installs | /var/log/apt/history.log, dpkg.log | /var/log/dnf.log |
| Kernel ring buffer | dmesg or journalctl -k | |
| Web server | /var/log/nginx/, /var/log/apache2/ | /var/log/nginx/, /var/log/httpd/ |
Debian 13 images may ship without rsyslog, in which case the journal is the only system log. That is fine; journalctl does everything the text files did, and more.
How do I read the journal?
journalctl -b -p warning --no-pager | tail -50 journalctl -u nginx.service --since "2 hours ago" journalctl -u postgresql@16-main -n 200 -o short-iso journalctl -f -u myapp.service
-b limits output to the current boot, -p warning hides anything below that priority, and -u picks one unit. Time filters accept plain English such as yesterday or exact stamps like "2026-12-02 03:00". -f follows new lines as they arrive, the journal equivalent of tail -f. Add yourself to the adm or systemd-journal group to read everything without sudo.
Why did the server reboot, and what happened before?
journalctl --list-boots | tail -5 journalctl -b -1 -e last -x reboot shutdown | head
-b -1 is the previous boot and -e jumps to its end, which shows the last lines written before the restart. A clean shutdown ends with systemd stopping units. A log that just stops mid-sentence points to a power cut or a hard reset. The journal only keeps old boots if it is persistent; on most images /var/log/journal exists and it is. If it is missing, create the folder and restart systemd-journald.
How do I read plain text logs efficiently?
sudo tail -n 100 -F /var/log/nginx/error.log sudo less +G /var/log/auth.log sudo zgrep -h 'Failed password' /var/log/auth.log* | wc -l sudo grep -c ' 502 ' /var/log/nginx/access.log
tail -F keeps following a file even after log rotation replaces it. less +G opens at the end; inside less, ? searches backward and F switches to follow mode. zgrep searches rotated .gz files together with the live one. For pattern tricks see The grep command.
How do I find errors fast during an incident?
- Start with
systemctl --failedto see which units are down. - Run
journalctl -u <unit> -n 80on each failed one; the cause is usually in the last few lines. - Check
journalctl -k -p err -bfor disk, memory or network driver errors. - Read the app's own log, since many apps write details there and only a short line to the journal.
- Note the time of the first error and look at every log around that minute.
How do I keep logs from eating the disk?
journalctl --disk-usage sudo journalctl --vacuum-size=800M echo 'SystemMaxUse=1G' | sudo tee -a /etc/systemd/journald.conf sudo systemctl restart systemd-journald
Text logs are rotated by logrotate, which runs daily from a systemd timer and reads /etc/logrotate.d/. For a busy app log, a drop-in like this keeps two weeks compressed:
/srv/shop/logs/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
copytruncate
}
Never delete a log a service still has open; the space is not freed until the process closes it. lsof command shows how to find those files.
Should I ship logs off the box?
For anything you would hate to lose, yes. A single machine has no second copy, so if the disk fails or someone breaks in and wipes logs, the evidence goes with it. Forwarding with rsyslog over TLS to a small second server, or sending to a self-hosted Loki or OpenSearch stack, keeps a copy elsewhere. Even a nightly Back up data with rsync of /var/log is better than nothing.
How do I search the journal by field instead of text?
Every journal entry carries structured fields, so you can filter on them directly rather than grepping text. journalctl _PID=2290 shows lines from one process, journalctl _UID=33 everything from the www-data account and journalctl SYSLOG_IDENTIFIER=sshd --since today all SSH daemon lines. journalctl -o verbose -n 1 prints one entry with every field it carries, which tells you what you can filter on. Field filters are faster than piping thousands of lines through grep and never match by accident.
Machines With Disk Space for Long Log History
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| E1 | Intel Xeon E3-1240 v3 | 4 / 8 | 16 GB DDR3 | 2x 240 GB SSD | 2x 1 Gbps | $30.52 | $91.56 (3 months) |
| S1 | Intel Xeon E-2276G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $53.32 | $53.32 (1 month) |
| S3 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $80.38 | $80.38 (1 month) |
Keep Reading
The grep command
grep from basics to power use: case, whole words, line numbers, context, recursion, regex flavors, only-matching output and speed tips.
Openlsof command
Use lsof to see which process holds a file, a port or a deleted log open, and free disk space without a reboot.
Opendmesg command
Read the Linux kernel ring buffer with dmesg: hardware detection, disk and network errors, out of memory kills, with readable timestamps.
OpenBack up data with rsync
Build dated, space-saving snapshot backups with rsync and hard links, pull them from a second machine and test restores.
OpenFAQ
Quick Answers
Ubuntu uses /var/log/syslog for general messages. /var/log/messages is the RHEL family name.
Run journalctl -b -1. It needs persistent journal storage in /var/log/journal.
Yes, after adding the account to the adm or systemd-journal group.
Pipe them: journalctl -u nginx --since today --no-pager > nginx-today.txt.
It reopens the file by name after rotation, so following continues across rotated logs.