Tailing the latest Apache error log

When debugging web server errors, my first instict is to check Apache’s error logs.
After navigating to the apache error log directory, I just tail the error log.
While this should be relatively simple, when Apache rotates the logs it can be a
little more cumbersome because we have to find which log is the most recent.
This usually involves the following steps (assuming we are in the directory that
contains the Apache error logs):

First, we must find the most recent log:

ls -tr error*

This produces a list similar to this:


Since this ls command gives us the most recent log file at the bottom of the list, we can now go onto the next step:

tail -f error_log.1294228800

While this works everytime, it just seems as if its too many steps. Instead of following the above process, lets cut it down to one step:

tail -f $(ls -tr error* | tail -1)

With this approach, we don’t even need to know the name of the log… as it will pull the last one for us!

~ by ityndall on January 5, 2011.

2 Responses to “Tailing the latest Apache error log”

  1. You could take that one step further and create an alias; e.g.,

    alias tail-error=’tail -f $(ls -tr /path/to/apache/logs/error* | tail -1)’

    Put that in your ~/.bashrc, log out, and log back in, and then all you need to do is type tail-error (or whatever you name it). 🙂

  2. […] version 2.1.9.cp21 Simple Fix to Increase Comments on Your BlogNobel economists have no simple fixTailing the latest Apache error log […]

Leave a Reply