When a service crashes or behaves oddly, the first reflex is to open its logs. But if you open a static file, you see a snapshot. What you need is a live stream: see the lines as they arrive, filter the errors while a deployment runs, watch several files at the same time.
On Linux, two tools cover this need: tail -f for plain files, journalctl -f for systemd journals. This guide shows you how to use them alone and together.
What you will learn
- Follow a log file in real time with
tail -fand--follow=name - Filter errors in real time in a pipeline with
grep --line-buffered - Watch several files at once with
tail -f - Query journalctl by unit, priority, time range or boot
- Choose the right tool for the log's source
In which context?
You are deploying a new version of an application and you want to see the logs when the service restarts. A cron job runs at night and you suspect an error you cannot reproduce during the day. A service is intermittent and you want to be alerted as soon as ERROR appears, without running a command every 30 seconds. Real-time log watching is a first-line skill in system administration: it gives you the information at the right moment, during the event, not after.
tail, follow plain files
Many services still write to text files under /var/log/, independently of systemd: nginx, apache, postgresql, or any home-grown application that redirects its output. For those, tail is the reading tool, and its follow mode turns a one-off read into continuous observation. Two points deserve your attention: file rotation and the behaviour of the buffer when you plug a filter behind it.
The basics
tail shows the last lines of a file. Without options, it shows 10:
tail /var/log/syslog # last 10 linestail -n 50 /var/log/syslog # last 50 linestail -n +100 /var/log/syslog # from line 100Follow mode: tail -f
-f (follow) opens the file and shows the new lines as they are written. It does not give the prompt back: it stays active until Ctrl+C:
tail -f /var/log/nginx/access.logtail -f vs tail --follow=name
This is an important distinction in production. A file descriptor is the number the kernel assigns to an open file: it stays attached to the content even if the file is renamed. tail -f holds on to this descriptor, while --follow=name checks the path again at regular intervals and reopens the new file as soon as it appears. The --retry option completes the second form by making it patient if the file disappears for a few moments.
| Option | Behaviour |
|---|---|
tail -f | Follows the file descriptor: after a rotation, it keeps reading the old renamed file |
tail --follow=name --retry (or tail -F) | Follows the file name, survives logrotate rotation |
# For logs with rotation (nginx, apache, syslog...)tail --follow=name --retry /var/log/nginx/access.logFollow several files
tail -f accepts several arguments. It prefixes each block with the file name:
tail -f /var/log/nginx/access.log /var/log/nginx/error.log==> /var/log/nginx/access.log <==192.168.1.10 - - [09/Apr/2026:10:05:00] "GET /api/users HTTP/1.1" 200 523
==> /var/log/nginx/error.log <==2026/04/09 10:05:01 [error] 1234#0: upstream timed outFilter in real time
On a busy server, a raw tail -f scrolls too fast to be read. The reflex is to plug a filter behind it, with a pipe (|), to keep only the lines you care about. This combination has a trap specific to real time: by default, commands in the middle of a pipe only write their output in blocks, which freezes the display for minutes.
grep --line-buffered: the essential option
In a normal pipeline, grep accumulates its output in a buffer before writing it, which breaks the real-time effect. --line-buffered forces writing line by line:
# Show only errors and warningstail -f /var/log/app.log | grep --line-buffered -iE 'error|warn'
# Exclude the monitoring requests (/health, /metrics)tail -f /var/log/nginx/access.log | grep --line-buffered -v '/health\|/metrics'
# Show HTTP 5xx errors in colourtail -f /var/log/nginx/access.log | grep --line-buffered --color=always '" 5[0-9][0-9] 'Chain several filters
Nothing prevents chaining several grep: the first selects, the following ones exclude the remaining noise. Each link of the pipe has its own buffer, so --line-buffered must be repeated on each of them, except the last one, which writes directly to the terminal. Forgetting the option on a single link is enough to freeze the whole display.
# Errors but not the monitoring errorstail -f /var/log/app.log \ | grep --line-buffered 'ERROR' \ | grep --line-buffered -v 'healthcheck'less +F, the interactive alternative
less +F starts in follow mode and lets you browse the history during the session:
less +F /var/log/syslogCtrl+C: stops following, lets you scroll with the arrowsF: resumes real-time followingq: quits
It is useful when you want both to see the new lines AND to go back through the history without quitting.
journalctl, the systemd journals
journalctl queries systemd's binary journal. Unlike plain files, this journal centralises the messages of every service, with metadata, priorities and boot numbering.
Real-time following
-f shows the latest entries then stays active, adding each new line as services write it, until Ctrl+C. Filters add up with this mode: -u restricts to one or several systemd units, -p to a priority level. Repeating -u shows the units interleaved in chronological order, which shows the real sequence between two services.
journalctl -f # every unit, livejournalctl -f -u nginx # nginx service onlyjournalctl -f -u nginx -u postgresql # nginx AND postgresqljournalctl -f -p err # errors only, liveFilter by systemd unit
The name passed to -u is that of the systemd unit, as systemctl list-units shows it; the .service suffix is optional. --no-pager turns off less and writes directly to the terminal, which is essential in a script or when you want to chain the output into another tool. -n limits the output to the most recent lines, the reflex not to scroll through months of history.
journalctl -u nginx --no-pager # nginx's whole historyjournalctl -u nginx -n 50 --no-pager # last 50 linesjournalctl -u nginx -f # liveFilter by priority
The levels follow the syslog convention (from the most to the least critical):
| Level | Value | Meaning |
|---|---|---|
emerg | 0 | System unusable |
alert | 1 | Immediate action required |
crit | 2 | Critical condition |
err | 3 | Errors |
warning | 4 | Warnings |
notice | 5 | Notable normal conditions |
info | 6 | Informational messages |
debug | 7 | Debug messages |
-p err filters the levels err and more critical (0 to 3):
journalctl -p err --since "1 hour ago" --no-pagerjournalctl -p warning --since today --no-pager # warnings and more criticalFilter by time range
--since and --until accept an absolute date (YYYY-MM-DD HH:MM:SS) as well as a relative expression in English, computed from the machine's current time. That is what lets you go back over an incident that is already over: you frame the window reported by the monitoring and you read only those minutes. Beware of the time zone: journalctl shows the server's local time, not yours.
journalctl --since "2026-04-09 10:00:00" --until "2026-04-09 11:00:00" --no-pagerjournalctl --since today --no-pagerjournalctl --since yesterday --no-pagerjournalctl --since "1 hour ago" --no-pagerFilter by system boot
journald assigns an identifier to each boot of the system and lets you refer to it by a relative number: 0 for the current boot, -1 for the previous one. This split is precious after an unwanted reboot, because the last lines before the outage are in the previous boot, not the current one. If --list-boots returns only one line, the journal is not persistent and the history stops at the last boot.
journalctl -b --no-pager # current bootjournalctl -b -1 --no-pager # previous bootjournalctl --list-boots # list every known bootIt is useful after a crash: journalctl -b -1 -p err shows the errors of the previous boot.
Kernel messages
-k keeps only the entries emitted by the kernel: hardware detection, disk errors, processes killed for lack of memory, packets rejected by the firewall. It is the first thing to look at when the failure seems to come from the machine rather than the application. Unlike dmesg, journalctl timestamps these messages with the real date, which lets you cross-check them with the services' logs.
journalctl -k --no-pager # kernel messages (dmesg equivalent)journalctl -k --since "1 hour ago" --no-pagerCombine journalctl and grep
journalctl filters on metadata (unit, priority, date), not on the message content. As soon as the search bears on a precise text, a pipe to grep or awk takes over. --no-pager then becomes mandatory: without it less intercepts the output and the pipe receives nothing usable. The second example counts the occurrences per service, a quick way to spot the noisiest component. The fifth field is process[PID]:: the sub() removes the PID, otherwise each process would be counted separately.
# Look for failed SSH connections (ssh unit on Debian and Ubuntu)journalctl -u sshd --since today --no-pager | grep 'Failed\|Invalid'
# Count the errors per service over the last hourjournalctl -p err --since "1 hour ago" --no-pager \ | awk '{sub(/\[[0-9]+\]:$|:$/, "", $5); print $5}' | sort | uniq -c | sort -rnChoose between tail -f and journalctl
The choice criterion is not a preference, it is the log's source. If the service itself writes to a file under /var/log/, tail reaches it directly; if it only writes to its standard output, systemd captures the stream and only journalctl sees it. When in doubt, journalctl -u <service> answers at once: if it only shows the service's starts and stops, its application messages go elsewhere, therefore to a file.
| Situation | Recommended tool |
|---|---|
Service with logs in /var/log/*.log | tail -f |
| systemd service without a dedicated log file | journalctl -f -u <service> |
| Filter by priority or time range | journalctl |
| Post-crash investigation (previous boot) | journalctl -b -1 |
| Follow several non-systemd files | tail -f file1 file2 |
| Interactive mode with history navigation | less +F |
Administration use cases
The commands below combine the building blocks seen above on real operational situations: accompanying a deployment, reacting to an error line, understanding why a service refuses to start, ranking the noisiest components. The last example skips no line: journalctl writes no header, and an NR>1 would throw away a real entry (measured on systemd 255). The while read loop deserves a remark: it handles each line as soon as it arrives, and only exists thanks to the --line-buffered on the grep before it. The commented logger line would send the alert to syslog instead of printing it.
# Watch a deployment: app + nginx logs at the same timetail -f /var/log/app/production.log /var/log/nginx/error.log
# Alert on errors during a deploymenttail --follow=name --retry /var/log/app/production.log \ | grep --line-buffered 'ERROR\|FATAL' \ | while read -r line; do echo "[ALERT] $line" # logger -t deploy_monitor "$line" # optional: send to syslog done
# Diagnose why a service did not startjournalctl -u my-service -b --no-pager | tail -n 30
# See every error since yesterdayjournalctl -p err --since yesterday --no-pager | grep -v 'kernel'
# Top of the noisiest services in errors (last hour)journalctl -p err --since "1 hour ago" --no-pager \ | awk '{sub(/\[[0-9]+\]:$|:$/, "", $5); print $5}' | sort | uniq -c | sort -rn | head -10Key points
tail -ffollows a file by descriptor;--follow=name --retry(ortail -F) survives rotation: use the second in production.grep --line-bufferedis mandatory in a pipeline withtail -fto avoid silent buffering.journalctl -f -u <service>is the systemd equivalent oftail -f, with no rotation risk.journalctl -b -1 -p erris the first reflex after a crash: errors of the previous boot.less +Flets you browse the history without leaving follow mode.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: sed: replace, delete and insert text
A new full quiz with random questions
Work again only on the questions you missed