Created
August 1, 2009 12:23
-
-
Save alvarobp/159648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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