brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tail -F keeps following a log after logrotate renames it

Tail
~/tips/tip-linux-tail-capital-f

tail -F /var/log/nginx/access.log

Follows a log file by name so it keeps working after the file is rotated.

You follow a log with tail -f, it goes quiet in the middle of the night, and you think the app stopped writing. Often the file was just rotated.

The fix is one capital letter:

tail -F /var/log/nginx/access.log

Lowercase -f follows the open file descriptor. When logrotate renames the file, tail keeps watching the old, now unused file. Capital -F follows the name, and retries when the file disappears or is replaced. It is shorthand for --follow=name --retry.

That also helps when you start tail before the log exists yet, for example while a service is still starting. It will wait and pick the file up when it shows up.

The caveat: after a rotation you may see a short notice that the file was replaced, and a few lines can fall between the old and new file. For systemd services, journalctl -f avoids the whole issue.

I would make capital F the default in my fingers for any log that a rotation tool manages. It costs nothing when no rotation happens.

Further reading: tail man page, On this site: journalctl –vacuum-size caps how much log space you keep, On this site: docker logs –since 10m -f shows only what just happened

More Tail tips tail -c 2000 export.json tail -f --pid=1234 build.log tail -f /var/log/nginx/access.log /var/log/nginx/error.log tail -n +2 export.csv All Tail tips (5) All topics

Link