The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




Thread: Directory sizes
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 09-24-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,117
Preßy,

ls -h is available only on GNU ls. So that is not a very general answer. Besides, the real thrust of the question is the mental conversion of bytes to megabytes.

3499990308 as displayed by ls represents bytes. To get it to megabytes, I want to drop the last 6 digits. 3499990308 is sort of how I "see" the number. Now I do evaluate that 990308 as I throw it away. I do that really by looking just at the leading nine. Since I am throwing away a "large" number, I add one to the number that I keep. 3499 + 1 = 3500 MB. Whether or not to add that one depends on the leading digit of what I threw away. If it's 5,6,7,8, or 9 then I add the one.

This is a compromise, I would use a more accurate algorithm if I were writing a program. But I can do this instantly and effortlessly.

Effectively, what I have done is to divide the number by 1,000,000. Perfect accuracy would have required dividing by 1,048,576. Using the bc program I see that the real answer is 3338 MB. With a file this big, I don't care about a lousy 162 MB.

29994 is too small. Well, ok, it is 0 MB. I simply never want to convert tiny sizes to megabytes. But kilobytes would work in this case. The rule is similiar to the above, but here I just drop 3 digits rather than 6. So I estimate that file at 30 KB. bc says the real answer is 29 KB. Again, close enough.

Notice that both of my estimates were high. That is guaranteed to be the case.