To view the last lines of a file, you use the companion command to head, which is called tail.
Just like head shows the beginning, tail shows the end of a file.
How to use tail:
The basic command shows the last 10 lines by default:
tail access.log
Viewing a specific number of lines:
Similar to head, you use the -n option to specify how many lines you want to see from the bottom:
tail -n 5 access.log
(This shows the last 5 lines.)
A Pro Tip: tail -f
One of the most powerful uses of tail is the -f (follow) flag. It allows you to watch a file in real-time as new lines are added. This is incredibly useful for monitoring log files while a program is running:
tail -f access.log
(Press Ctrl + C to stop watching.)
In summary: Use head for the top and tail for the bottom! Do you want to try running tail on your access.log now?