Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to estimate the amount of disk space used by a directory using the following command.

du -sh dir_name

which does not calculate the hidden directories. In the man page of du there is no info regarding it. How to calculate the amount of disk space used by the directories including the hidden files.

share|improve this question

migrated from Oct 3 '11 at 11:30

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

Actually it does, here is the proof:

mkdir .test
echo "hi" > .test/appo
du -a
4       ./.test/appo
8       ./.test
12      .

The -a option is used to explicitly show which files were counted.

Are you using du *?

share|improve this answer
+1 for ... you maybe using "du *" ? – sehe Oct 3 '11 at 11:34
I am not using "du *". I forgot to mention in the question that i need the total summary summary. so if i use both -a and -s as in du -as i get an error message saying "du: cannot both summarize and show all entries". This is one issue. The other thing is that i even with du -a i get to see only the first level files. i.e unable to see files inside hidden directories. – Talespin_Kit Oct 3 '11 at 11:50
I just added -a to show all files being counted, just don't add that flag, it only affect the display, not the totals. I showed you a counter-example that instead hidden directories are counted. – stivlo Oct 3 '11 at 11:56
now i found the problem. The problem was the hidden directory was a symbolic link, So i had to use "du -Lsh dir_name". Thanks. – Talespin_Kit Oct 3 '11 at 12:47
ah, I see, glad that you found it, cheers. – stivlo Oct 3 '11 at 13:03

This command shows you the summarized size of hidden directories

du -hs .[^.]*

share|improve this answer

FYI, for estimating the size occupied by various directories, its much better to use ncdu

You can navigate in the ncurses GUI between various directories and it will show the size of each directories. If I am using du, I would have to execute du command for each directory I want to check for which can be cumbersome. You can sort the directories according to the size occupied too in the ncurses GUI.

share|improve this answer
Please edit your answer to indicate why you believe ncdu to be "much better". The linked page doesn't really say anything about it other than that it's an ncurses-based version of du. Aside from a fancier display method, there's no obvious indication of any functional difference. – Dave Sherohman Oct 4 '11 at 10:15

The correct command is : du -hs $(ls -A)

$ du -hs $(ls -A)
0   test
0   .test

du -hs .* *, as mentioned in another answer, is not correct if you want to list all files and subdirectories (including hidden ones).

Example :

$ touch test
$ touch .test
$ echo *
$ echo .* *
. .. .test test
$ du -hs .* *
4,0K    .
1,8G    ..

Why does du behave like this? Because you use -s that summarize the result and that all files and subdirectories are children of . so du -hs does not list them!

share|improve this answer

It does and it does not. Example:

In the home directory: (only one user exist)

du -sh /home/*
2.6G    /home/user

in the user directory: (huge difference between the sums)

du -sh *
61M     bin
2.0M    dump-20130124104823.tar.gz
651M    public_html
472K    twitter-2.0.0.gem
11M     wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2

and the reason is:

du -sh /home/user/.rvm/
1.9G    /home/user/.rvm/

du will calculate hidden directories while descending into subdirectories, but in the current directory the * simply does not match to .directory_name pattern so the current directory hidden elementes will be omitted.

It took me some time to figure out, and as shadyabhi recommends it would have been obvious if i had used ncdu.

share|improve this answer

The correct command is : du -hs .* *

share|improve this answer
Some additional information would make this an acceptable answer. – Ramhound Sep 23 '14 at 12:07

You must log in to answer this question.

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