Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wrote a quick script to perform a "df | grep /my/directory/here" and pull out the amount of used space. When the number didn't look right to me, I went back and noticed a difference between df and df -h. When I simply do a "df" I might get a number for "used" as 197370964. If I do a df -h it will tell me 189G.
Realizing that the number that df is giving me is the number of 1024 blocks, wouldn't that mean that 197370964 should translate to 202GB (197370964 x 1024)? I don't understand the discrepancy. How does one manually convert the # of 1024 blocks to a human-readable number?
Thanks!
The answer is simple:
"df" shows the output in 1K blocks. Divide it by 1024 to get megabytes, and again by the same 1024 to get gigabytes. There's your 188GB.
your looking at it wrong, 197370964 / 1024 = ~192,745. 192,745 / 1024 = ~188. I lost the decimal points each time, but roughly it comes out to 188.2 GB (well technically GiB but I prefer to use GB by it's original meaning). Also -h is short for --human-readable as it goes anyway.
Looks like I was beaten to it, oh well, not gunna remove it now anyways =P.
Last edited by r3sistance; 02-11-2009 at 09:07 AM.
Thanks to all who replied, what you say makes sense of course. However, I'm still confused why my OS would report 189G and not 188G if the 'true' answer is 188.2. Shouldn't it round down?
The reason I'm re-visiting this issue of course is because the larger the number gets, the bigger the discrepancy. To give full disk usage statistics I'm giving the total disk space allocated for a set of servers... each server is showing 2.1T when I do a "df -h". If I just do a "df" and then /1024 3 times (to get gigs) I get 2.01G:
2163071696 / 1024 = 2112374.703125 MB
2112374.703125 / 1024 = 2062.8659210205078125 GB
2062.8659210205078125 / 1024 = 2.01451750099658966064453125 TB
I realize it's not much of a difference, but how do I know what the 'true' value is? Is Linux automatically rounding up every time?
Now that df -H has been brought up, I tried that and I got back 2.3T. So is the allocated disk space for this filesystem 2.1T, 2.01T, or 2.3T? And why the differences?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.