Making heads and tails of text files...
By default, the head and tail commands each give an output of ten lines. That's not bad, and for many things it is all that we need. But there are times that it would be nice to get more or less from these commands.
To get head to give us a different number of lines, just add the number of lines that you wish to be returned following a hyphen, as it if were a normal flag. Here is an example to return the top five lines of a file.
# head -5 /var/log/messagesStrangely, and I have no explanation for this, tail works similarly but not exactly the same. The tail command needs a "-n" flag followed by the number of lines that we wish to extract. So if we wanted to see the final eighteen lines of a text file we would do it like so:
# tail -n 18 /var/log/messages