Skip to content

Instantly share code, notes, and snippets.

@kschiess
Created December 10, 2010 15:24
Show Gist options
  • Save kschiess/736328 to your computer and use it in GitHub Desktop.
Save kschiess/736328 to your computer and use it in GitHub Desktop.
Gathers key information about a directory.
#!/opt/csw/bin/ruby
directory = ARGV.join(' ')
count = ['?', '?']
# get users, which have created files in dir
#
users = Hash.new(0)
`tree -u '#{directory}'`.split("\n").each do |line|
user = line.scan(/\[([^\]]*)\]/).flatten.first
if user
user = user.strip
users[user] += 1
end
if md=line.match(/(\d+) director(?:y|ies), (\d+) files?/)
count = md[1..2]
end
end
# get usage of directory
usage = `du -sh '#{directory}'`.chomp
# find the newest file
cmd = %Q{
find #{directory} -type f |
ruby -n -e'print $_.gsub(/([^A-Za-z0-9_\\-.,\:\\/\@\\n])/n) { "\\\\#\$1" }' |
xargs ls -lrtE #{directory} | tail -1
}
# puts cmd
newest = `#{cmd}`
date = '???'
if md=newest.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)
date = md[0]
end
printf "%-28s %3s %3s %s %s\n",
usage,
count.first,
count.last,
date,
users.map{|u| "#{u.first}(#{u.last.to_s}) " }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment