Home / Localhost / tail -f

tail -f: watch a log file live (and -F for rotated logs)

Use tail -f to follow a log as it grows, tail -n to see more lines, and tail -F so it keeps working when the log file is rotated.

tail prints the last 10 lines of a file. Add -f and it keeps running, printing new lines as they are written, which is how you watch a log while you reproduce a problem.

Watch a log while you test

  1. Run tail -f /var/log/nginx/error.log (use your own log path).
  2. Reproduce the problem in your browser or app.
  3. Read the new lines as they appear.
  4. Press Ctrl+C to stop watching.

Commands you can copy

Follow a log live
tail -f /var/log/nginx/error.log
Last 50 lines, then follow
tail -n 50 -f app.log
Survive log rotation
tail -F app.log
Last 100 lines only
tail -n 100 app.log
Everything from line 20
tail -n +20 app.log
Follow two files
tail -f access.log error.log
Follow a systemd service log
journalctl -u myapp -f

tail options explained

-f vs -F
With no argument, -f follows the open file (the file descriptor), so it keeps following the file even after it is renamed. -F is the same as --follow=name --retry: it follows the file by name and keeps trying if the file is missing, which suits rotated logs.
-n N and -n +N
-n 50 prints the last 50 lines instead of 10. -n +20 starts printing at line 20, counted from the start of the file.
The log stops updating after rotation
The old file was renamed and tail is still reading it. Restart with tail -F. The nginx commands page shows how to reopen logs.
No such file or directory
The log path is wrong or the program has not created it yet. -F waits for it to appear.
Permission denied
Many logs under /var/log are readable only by root or a group. Use sudo, or add your user to that group.

Questions about tail -f

How do I stop tail -f?
Press Ctrl+C.
What is the default number of lines?
10 lines of each file.
What does tail -F do?
It follows the file by name and retries if the file is inaccessible, so it keeps working through log rotation.
How do I follow a service log on systemd?
Use journalctl -u servicename -f.

Updated 2026-10-27

Related pages