Skip to content

Instantly share code, notes, and snippets.

@alvarobp
Created August 1, 2009 12:23
Show Gist options
  • Save alvarobp/159648 to your computer and use it in GitHub Desktop.
Save alvarobp/159648 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if ARGV.size == 0
puts "Usage: findlogs <directory>"
exit
end
require 'find'
class Numeric
def to_human
units = %w{B KB MB GB TB}
e = (Math.log(self)/Math.log(1024)).floor
s = "%.3f" % (to_f / 1024**e)
s.sub(/\.?0*$/, units[e])
end
end
root_dir = ARGV.first
Find.find(root_dir) do |path|
size = File.size?(path)
puts "#{size.nil? ? '0'.ljust(20) : size.to_human.ljust(20)} - #{path}" if path =~ /\.log$/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment