LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 08:34 AM   #1
sudz28
LQ Newbie
 
Registered: Nov 2008
Location: Finksburg, Maryland
Posts: 9

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, 09: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, 09:05 AM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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.
 
Old 02-11-2009, 12:23 PM   #4
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

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

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, 12:12 PM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
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, 03: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, 03:17 PM   #8
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

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


Reply



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 04:08 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 09:40 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 01:30 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 01:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:34 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
Open Source Consulting | Domain Registration