Tail

The tail command outputs part of a file including its end. Again, by default it outputs the last ten lines, but if used with a numerical option it can output any number of lines in the same way as described previously for the head command.

A very useful option is -f (for follow), which outputs the appended data as the file grows. This allows you to watch a log file, for example, while you make a change somewhere else:

# tail -f /var/log/messages

Combining head and tai within a file:

clearly gives you an easy way of getting certain particular lines from [email protected]: -line 1

line line line line line

So you've extracted the last two of the first five lines of the file, in other words, the fourth and fifth lines only. Similar logic allows you to use head and tail together to extract any range of lines from a file.

Was this article helpful?

0 0

Post a comment