Skip to content

Instantly share code, notes, and snippets.

@mbailey
Created October 25, 2010 06:00
Show Gist options
  • Save mbailey/644473 to your computer and use it in GitHub Desktop.
Save mbailey/644473 to your computer and use it in GitHub Desktop.
tail.rb
#!/usr/bin/env ruby
filename = ARGV[0]
end_marker = 0
offset_increment = 1000
lines = []
fh = File.open filename
while lines.size < 10
current_offset = end_marker + offset_increment
fh.seek(-current_offset, IO::SEEK_END) || fh.rewind
buf = fh.read(current_offset - end_marker).split("\n")
lines.insert(0, *buf)
end_marker += current_offset
end
puts lines.last 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment