4

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?

1 Answer 1

6

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.

3
  • thanks i just tried and du -hs * reports similar file size as du -hsc *. Why do du -hs . report 1.2 GB then? Aug 20, 2015 at 21:34
  • Read my answer again. du -hsc * will not report a different size than du -hs *. All the -c flag does is provide a total size of the files and directories it checked, so you don't have to add it up manually. Check to see if you have any files or directories in that location that begin with a period, and see how much space they're taking up.
    – Gene
    Aug 20, 2015 at 21:37
  • Oh i see, that the .git directory is taking up 600 MB. Thanks Aug 20, 2015 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .