How to Follow a Log File Live in Linux
Follow new log entries with tail and handle log rotation correctly.
When debugging a running service, repeatedly reopening a log wastes time. `tail -f` keeps the file open and displays new lines as they arrive.
Step by step
1 Follow the file
$ tail -f app.log Prints existing final lines and waits for new output.
2 Start with more context
$ tail -n 100 -f app.log Shows the last 100 lines and then continues following.
3 Follow through rotation
$ tail -F app.log The capital F keeps trying to reopen the pathname if the underlying file is replaced during log rotation.
4 Filter the stream
$ tail -f app.log | grep --line-buffered -i error Shows only matching new lines while preserving immediate output.
Tips worth knowing
- Use Ctrl+C to stop.
- Use `journalctl -f -u SERVICE` for systemd-managed services instead of following a raw journal file.
- If tail -f appears stuck, verify that the application is writing to the file you are watching.
Frequently asked questions
What does tail -f do?
It follows a file and prints new data as it is appended.
What is tail -F?
It follows the pathname and can reopen the file after rotation or replacement.
How do I follow only errors?
Pipe tail into grep with `--line-buffered` so matches are displayed promptly.
The commands behind it
Print the first or last lines of a file — including live log following with tail -f.
journalctlQuery the system journal: by service, time window, priority — and follow live.
grepFind lines matching a pattern in files or piped input — the workhorse of text search.
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.