Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Oct 3 '11 at 11:30

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

add comment

4 Answers

up vote 5 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  
+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
1  
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
add comment

This command shows you the summarized size of hidden directories

du -hs .[^.]*

share|improve this answer
add comment

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
1  
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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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