tail - See the Last Lines
Learn tail for viewing the end of files. Check recent logs and grab bottom results.
tail: Show Me the End
You have a log file that's been collecting data for months. You only care about the most recent entries:
tail log.txt
Last 10 lines. The freshest data. That's tail.
Specifying How Many Lines
Last 5 lines:
tail -n 5 file.txt
Last 50 lines:
tail -n 50 file.txt
Or shorthand:
tail -5 file.txt
tail -50 file.txt
Skip the Header
Here's a trick: tail -n +2 means "from line 2 onward" - effectively skipping the header:
tail -n +2 data.csv
All data except the first line. Useful for CSVs with headers.
In Pipelines
Bottom 10 results after sorting:
sort -n scores.txt | tail
Last few errors:
grep "error" log.txt | tail -5
Just the Last Line
tail -n 1 file.txt
Sometimes that's all you need.
Quick Reference
| What you want | Command |
|---------------|---------|
| Last 10 lines | tail file |
| Last N lines | tail -n N file or tail -N file |
| Skip first line | tail -n +2 file |
| Just last line | tail -n 1 file |
See Also
- head - the opposite (beginning of file)
- cat - whole file
Practice
In CTF challenges, tail helps you check recent log entries and grab the lowest values from sorted data.
tail is for recency. When you want the latest, look at the end.