LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Difference between "df -h" and just "df"? (https://www.linuxquestions.org/questions/linux-newbie-8/difference-between-df-h-and-just-df-703879/)

sudz28 02-11-2009 08:34 AM

Difference between "df -h" and just "df"?
 
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!

merer 02-11-2009 09:02 AM

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.

r3sistance 02-11-2009 09:05 AM

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.

raskin 02-11-2009 12:23 PM

By the way, "df -H" prints in decimal (or SI, if you prefer) gigabytes

sudz28 03-03-2009 12:03 PM

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?

raskin 03-03-2009 12:12 PM

The difference is because 1000 != 1024. "df -H" should be ignored in most cases. How 2.1T appears is a bit of a puzzle for me..

3rods 03-03-2009 03:09 PM

I always remember it as making things "human readable".

raskin 03-03-2009 03:17 PM

-h is human readable. -H is (int this case) something like that, but not quite.


All times are GMT -5. The time now is 02:28 AM.