Skip to content


How to view live updates in a file under Linux

Linux

If you administer a Linux server or are a developer it is quite likely that you might need to watch a file to check for live updates to it. It could be a log file which you want to keep an eye on to see if any errors or messages appear, or it could just be a file with some data written into it. Here’s a way you can have that file update itself rather than your having to hit the refresh button constantly.

Say you want to monitor the Apache web server log file, /var/log/http/access.log. Use the following command to get live updates:

# tail -f /var/log/http/access.log

When you hit the Return key you should see the last few entries in the file (if there are any) and then the command will wait for further updates to the file and update automatically. One drawback of this command is that you can not scroll up or down using tail. Another drawback of this command is that if you are monitoring a file that gets rolled (the file gets moved to another file and a new blank file is used instead of the first one), then this command will stop the updates. We have a solution for the second problem. Use the following syntax:

# tail -F /var/log/http/access.log

The upper case -F ensures that even if the file rolls it will continue reading from the new file, which is quite useful. I usually just use this option regardless of whether I think the file might roll or not.

Posted in Linux.

Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

 

You can always opt out of this email subscription at any time.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.