Text
tail
Print the end of files and follow growing logs.
textfilelogsfollowend
Additional Notes
tail prints the last part of a file. By default, it shows the last 10 lines.
It is especially useful for logs because tail -f follows new lines as they are written.
Syntax
tail [options] [file...]
Parameters
options: Flags that change howtailbehaves.file: Text file to read or process.
Common Options
-n N,--lines=N: Print the lastNlines.-c N,--bytes=N: Print the lastNbytes.-f,--follow: Keep watching the file for new lines.-F: Follow by filename and retry if the file is rotated or recreated.-q,--quiet: Do not print file headers.-v,--verbose: Always print file headers.
Examples
tail app.log
Show the last 10 lines.
tail -n 50 app.log
Show the last 50 lines.
tail -f /var/log/syslog
Follow a log file live.
tail -F /var/log/nginx/access.log
Follow a log even if it is rotated.
journalctl -u ssh -f
For systemd services, this is often a better live-log command.
Practical Notes
- Press
Ctrl+Cto stoptail -f. - Use
tail -Ffor logs that may rotate. - Use
grepwithtailto filter live logs:tail -f app.log | grep error. - Use
headto view the start of a file.