The tail command

output the last part of files 14 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-n, --lines=[+]NUM
output the last NUM lines, instead of the last 10; or use -n +NUM to skip NUM-1 lines at the start
-f, --follow[={name|descriptor}]
output appended data as the file grows; an absent option argument means 'descriptor'

Examples

tail /var/log/syslog

Last 10 lines

tail -n 50 /var/log/syslog

Last 50 lines

tail -f /var/log/syslog

Follow: real-time updates!

head -20 file.txt | tail -10
tail -f /var/log/nginx/access.log

Watch web server requests live

tail -n +2 data.csv

Skip header line (print from line 2)

history | tail -20

Last 20 commands

tail -f wget-log

Monitor progress

tail -n 5 /var/log/nginx/access.log
tail /var/log/nginx/error.log
ls -t ~/backups/docs-*.tar.gz | tail -n +4

Everything after the 3rd line: the old ones

ls -t ~/backups/docs-*.tar.gz | tail -n +4 | xargs -r rm

…deleted (-r: not when there are none)

tail -n +2 ~/data/sales.csv

Everything but the header line

sudo tail /var/log/nginx/error.log

nginx says why, and where it tried to connect

Lessons that use tail

Related commands