The head and tail commands allow you to see a specified number of lines from the top or bottom of a file. The tail command has the very useful feature that you can use tail -f to keep an eye on a file as it grows. This is particularly useful for watching what is being written to a log file while you make changes in the system. Consider the following examples:
■ head -n5 /etc/passwd: Prints the first five lines of the file /etc/passwd to the screen.
■ tail -n5/etc/passwd: Prints the last five lines of /etc/passwd to the screen.
■ tail -f /var/log/messages: Views the last few lines of /var/log/messages and continues to display changes to the end of the file in real time (-f is for "follow"; it follows changes as they happen).
Was this article helpful?