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

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

head & tail

Print the first or last lines of a file — including live log following with tail -f.

journalctl

Query the system journal: by service, time window, priority — and follow live.

grep

Find lines matching a pattern in files or piped input — the workhorse of text search.

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.