# Tail, start reading at EOF

**URL:** <https://www.ruby-forum.com/t/tail-start-reading-at-eof/112701>\
**Category:** Ruby\
**Created:** [August 22, 2007, 11:21am UTC](https://www.ruby-forum.com/t/tail-start-reading-at-eof/112701 "2007-08-22T11:21:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [August 22, 2007, 11:21am UTC](https://www.ruby-forum.com/t/tail-start-reading-at-eof/112701/1 "2007-08-22T11:21:26Z")

</div>

Hi,

how to alter tail function to start at the end  
of the file, not reading the lines already existing in file ? =

File = File.open(ARGV[0])  
while File.exists?(file.path)  
puts file.gets while !file.eof?  
sleep(1)  
end

Regards, Gilbert

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [August 22, 2007, 12:14pm UTC](https://www.ruby-forum.com/t/tail-start-reading-at-eof/112701/2 "2007-08-22T12:14:33Z")

</div>

Hi,

Am Mittwoch, 22. Aug 2007, 18:20:12 +0900 schrieb Rebhan, Gilbert:

> how to alter tail function to start at the end  
> of the file, not reading the lines already existing in file ? =

file.seek 0, IO::SEEK\_END

> File = File.open(ARGV[0])  
> while File.exists?(file.path)  
> puts file.gets while !file.eof?  
> sleep(1)  
> end

File#eof? does not work here. When the file has been  
extended it still returns true even though File#gets will  
return a String object.

Bertram

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [September 25, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/tail-start-reading-at-eof/112701/3 "2007-09-25T23:02:36Z")

</div>

On Aug 22, 2007, at 6:27 AM, Rebhan, Gilbert wrote:

> > how to alter tail function to start at the end
> 
> end  
> end
> 
> Anything to improve ?
> 
> Regards, Gilbert

gem install file-tail

Then look at the rdoc for it. There’s an example that does an  
implementation of the Unix tail command. It’s a lot more capable  
that what you have here, but if you wanted to start some number of  
lines before the EOF, the file-tail gem is really what you want.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
