Linux
linuxlinux-commandsReferenceBeginner
Output Last Part of Files & Stream Logs (tail)
Output the last lines of files and stream newly appended log entries in real time using tail -f.
Verified: 2026-09-30
Tested on:linux Ubuntu 24.04 / Debian 12
Platforms:
linuxmacos
#linux#tail#logs#files#cli
Command
tail -f /var/log/nginx/access.log
Short Description
tail prints the last part of a file (default 10 lines). The -f (follow) option keeps the file open and outputs new lines in real time as they are appended.
Examples
1. View Last 20 Lines
tail -n 20 /var/log/syslog2. Follow Live Log Stream (-f)
tail -f /var/log/nginx/error.log3. Follow with Retry on File Rotation (-F)
Keeps tracking the log file even if it is rotated, truncated, or recreated by logrotate:
tail -F /var/log/app.log4. Show Last 50 Lines and Continue Following
tail -n 50 -f /var/log/postgresql/postgresql-16-main.log