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/syslogLast 10 lines
tail -n 50 /var/log/syslogLast 50 lines
tail -f /var/log/syslogFollow: real-time updates!
head -20 file.txt | tail -10
tail -f /var/log/nginx/access.logWatch web server requests live
tail -n +2 data.csvSkip header line (print from line 2)
history | tail -20Last 20 commands
tail -f wget-logMonitor progress
tail -n 5 /var/log/nginx/access.log
tail /var/log/nginx/error.log
ls -t ~/backups/docs-*.tar.gz | tail -n +4Everything 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.csvEverything but the header line
sudo tail /var/log/nginx/error.lognginx says why, and where it tried to connect
Lessons that use tail
- head & tail — First and Last Lines
- Pipes & Redirection
- wget — Downloading Files
- Reading the Logs
- Project: Nightly Backup
- Project: Sales Report from a CSV
- Mission: 502 Bad Gateway
- Mission: 403 Forbidden