Reading logs with ‘tac’

Logs are usefull for debugging and tracing what your code is doing, and what has done in the past.

I started using ‘tac’ when reading logs, specially when I need to see what happened recently.
$ tac that_log.log | less

From man tac:
tac - concatenate and print files in reverse
So with ‘tac’ you get the last line first. Which is nice if you don’t need to see lines from long ago.

print files in reverse
print files in reverse

After using tac for a while, I feel it is better to read from end to beginning, you read the error first and then what happened before. I think reading the error first makes you be more alert to read the following lines paying more attention.

If just using less to read the last line, you has to press Shift-g and wait a moment to get the last line, and sometimes with large files less hangs for a while.
Another option is to use tail -n<lines> to get the last lines right away, but usually <lines> are not enough.

Leave a Reply

Your email address will not be published. Required fields are marked *