# Needing a little help with a ruby program

**URL:** <https://www.ruby-forum.com/t/needing-a-little-help-with-a-ruby-program/150706>\
**Category:** Ruby\
**Created:** [October 11, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/needing-a-little-help-with-a-ruby-program/150706 "2008-10-11T20:55:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/needing-a-little-help-with-a-ruby-program/150706/1 "2008-10-11T20:55:52Z")

</div>

Ok, so this is what I need to do for the program. I am not the best  
programmer in the world and I need a little help.

Assignment:

Create a program that obtains disk usage information from du and uses  
it to print a histogram of the disk usage of the directories given as  
command line arguments. The histogram should consist of a string with  
one hash mark per megabyte of disk usage.

This is what I have so far.

require ‘fileutils’

specified\_directory = Dir.new("#{ARGV[0]}")

disk\_usage\_info = `du #{specified_directory} -a`

file\_size = Hash.new(0)

disk\_usage\_file.each\_line do |file, size|  
#Builds the hash with the filename and the sizes

end

file\_size.each do|file, size|  
#changes value to histogram of numbers and shows results

```
    size = '#' * size / 1024

    if times < 0
      puts file +"\t | " + size

    else
      puts file

  end

end

```

I think I have the first part and the last part down pretty well, I am  
stuck on how to get the du output into the hash so I can output it  
correctly. Any help would be appreciated.

Thanks,

Spudicus87

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/needing-a-little-help-with-a-ruby-program/150706/2 "2008-10-11T21:01:44Z")

</div>

On Oct 11, 2:52 pm, removed\_email\_address@domain.invalid wrote:

> This is what I have so far.  
> #Builds the hash with the filename and the sizes
> 
> ```
> else
> puts file
> 
> end
> 
> end
> 
> ```
> 
> I think I have the first part and the last part down pretty well, I am  
> stuck on how to get the du output into the hash so I can output it  
> correctly. Any help would be appreciated.

Study Regexp.

T.
