The file and dir sizes of du -hs * is not consistent with du -hs

When I run the bash command du -hs ., the output is

1.2G .

When I run the bash command du -hs *, the output is

108K    action
4.0K    activate.php
8.0K    browse.php
584K    captcha
164K    class
4.0K    clearcache
388K    cms
4.0K    comment.complete.php
4.0K    contact.php
530M    docs
116K    documentation
24K     DONE.txt
21M     em
4.0K    footer.php
4.0K    forgot.php
4.0K    header.php
196K    images
264K    includes
8.0K    index.php
168K    js
4.0K    login.php
4.0K    logout.php
4.0K    mail.confirmation.php
4.0K    mail.php
4.0K    news.item.php
4.0K    news.php
4.0K    profile.edit.php
4.0K    profile.php
4.0K    reset.confirmation.php
4.0K    robots.txt
4.0K    signup.confirmation.php
4.0K    signup.php
4.0K    svnstatus
4.0K    svnunknown
4.0K    TODO.txt
16M     tpl

If you add up all the file and dir size of the du -hs * output, it's about 600MB short of the du -hs . command. How do I figure out what's causing the 600MB? And why is there such a big discrepancy between the two commands?


Solution 1:

The du -hs * command will only report on files which will match that wildcard. That wildcard will not include any files or directories that begin with a period.

The dh -sh command will check . (the current directory) so it will check everything under that directory, including any files beginning with a period.

For example:

$ du -shc *
2.0M    file.1
4.0M    file.2
5.9M    file.3
 12M    total

$ du -shc
 24M    .
 24M    total

$ ls -la 
total 48576
drwxr-xr-x    8 John  Bovi      272 Aug 20 14:26 .
drwxr-xr-x  243 John  Bovi     8262 Aug 20 14:25 ..
-rw-r--r--    1 John  Bovi  2097152 Aug 20 14:26 .file.1
-rw-r--r--    1 John  Bovi  4145152 Aug 20 14:26 .file.2
-rw-r--r--    1 John  Bovi  6193152 Aug 20 14:26 .file.3
-rw-r--r--    1 John  Bovi  2097152 Aug 20 14:26 file.1
-rw-r--r--    1 John  Bovi  4145152 Aug 20 14:26 file.2
-rw-r--r--    1 John  Bovi  6193152 Aug 20 14:26 file.3

An aside:

To make things easier, instead of du -hs * use du -hsc *. It will provide a total so you don't have to add it up manually.