How to view a live logfile in realtime, on Linux

As a system admin or even just a Linux enthusiast you will most likely find yourself dabbling within log files from time to time, while troubleshooting it can often help to watch the logs come into your physical files as they occur, instead of searching for them after the event.

One example might be the apache error.log for a web server, if you navigate to the directory you can run the following command to get a live output of the file.

tail -f ./error.log

Then replicate your problem and have a look at what log’s come through.
Some log files like the one above can be quite busy, especially something like a web access log on your live web server, so it’s also a good idea to filter your output using grep.

In the example below, I want to see all errors, but only for the web client having the errors (my PC)

tail -f ./error.log | grep 192.168.0.123

As you can see it’s just a simple case of piping the output into the grep command.
Once your done with either command just hit ctrl + c to cancel out of the live trace.

>Ctrl^C

Technology enthusiastic with many ongoing online projects one of which is this personal blog PingBin. While also working full time within a data center designing and maintaining the network infrastructure.

1 comments On How to view a live logfile in realtime, on Linux

Leave a Reply to Kimberly Jane Olsen Cancel Reply

Your email address will not be published.