I think my du command is confused.

% du -shc DIR ...
6123941496      total

% du -shc DIR ...
6.1G    total

% du -sc --si DIR ...
6.6G    total

I've tried giving LANG=C and double-checking the result in a spreadsheet. It looks like -h already outputs using powers of 1000 (--si), and --si gives wrong answer. I think the correct answer should be 5.7G for -h and 6.1G for --si. So what happens here?

% du --version
du (GNU coreutils) 8.20

% uname -a
Linux XXX 3.9-1-amd64 #1 SMP Debian 3.9.8-1 x86_64 GNU/Linux
  • 3
    Please include the actual commands. What do the ... represent? You seem to have run the exact same command twice and have gotten different output, is that so? Have you read the explanation of the size modifiers in man du? – terdon Oct 10 '13 at 4:06

Repeat your tests using the --apparent-size switch.

$ du -shc --apparent-size DIR ...

excerpt from du man page

       print  apparent sizes, rather than disk usage; although the apparent size is
       usually smaller, it may be larger due to holes in (`sparse') files, internal 
       fragmentation, indirect blocks, and the like
  • 1
    Ah, so apparently -b is equivalent to '--apparent-size --block-size=1'. I missed that. Using 'du -shc --apparent-size' now correctly gives 5.7G now. Thanks! – Gerry Lufwansa Oct 10 '13 at 5:31
  • @GerryLufwansa - yeah when you start mixing in different filesystems or mounted CIFS ones it becomes really noticeable. I always use either -b or --apparent-size. – slm Oct 10 '13 at 11:34
  • ... and the difference can get really huge with HSM systems, where migrated files report 0 (or something like a few kB) without --apparent-size. – Ansgar Esztermann Oct 10 '13 at 11:49
  • Any solution for the du that comes with Mac OS X? – Alec Jacobson Jun 13 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.