LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-11-2009, 09:34 AM   #1
sudz28
LQ Newbie
 
Registered: Nov 2008
Location: Finksburg, Maryland
Posts: 7

Rep: Reputation: 1
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!
 
Old 02-11-2009, 10:02 AM   #2
merer
LQ Newbie
 
Registered: Jul 2007
Location: Vilnius,Lithuania
Distribution: Slackware 12.2
Posts: 20

Rep: Reputation: 1
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.
 
Old 02-11-2009, 10:05 AM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
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 10:07 AM.
 
Old 02-11-2009, 01:23 PM   #4
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
By the way, "df -H" prints in decimal (or SI, if you prefer) gigabytes
 
Old 03-03-2009, 01:03 PM   #5
sudz28
LQ Newbie
 
Registered: Nov 2008
Location: Finksburg, Maryland
Posts: 7

Original Poster
Rep: Reputation: 1
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?
 
Old 03-03-2009, 01:12 PM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
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..
 
Old 03-03-2009, 04:09 PM   #7
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
I always remember it as making things "human readable".
 
Old 03-03-2009, 04:17 PM   #8
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 05:08 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 09:31 AM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 10:40 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 02:30 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 02:42 AM


All times are GMT -5. The time now is 03:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration