Watching a file on disk

Paul Reinheimer wrote an article on a bug he was trying to solve.

He wrote:

Something I would love to have: An application that watched a file on disk, reporting all versions of the file over time. tail -f wont work as the file is a single line long, the line is changed but no new lines are added. I'm aware of similar tools for windows, none for mac/linux.

If you want to watch the last lines of a file to see when it changes, try this in linux:

watch tail /path/to/file

Every 2 seconds, it will run tail on your file and display you the last 10 lines.
DO NOT use the "tail -f" when using watch.

If the last line changed, you will see it appear in the next 2 seconds.

If you want to watch only line 30:

watch 'head -30 myfile | tail -1'

The watch utility seem to be installed by default on distribution like ubuntu and Suse.

PS: I tried posting this as a comment on Paul's blog but it told me:

Your comment did not contain a Session-Hash. Comments can only be made on this blog when having cookies enabled!
Your comment could not be added because comments for this entry have either been disabled, you entered invalid data, or your comment was caught by anti-spam measurements.


Thanks for the heads up on the tool, I'll take a look at this tonight! :)


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You may post PHP code. You should include <?php ?> tags.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options