I want to get the size of all directories within a specific directory. I was thinking something like
find . -type d -exec du -sh {} \;
But that returns all directories recursively. How can I limit the depth?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityWhy use find at all and not simply glob for directories?
du -shc */
-maxdepth 1
is specified before the -type d
argument). The OSX version of du
will give a syntax error with du -shc */
.
Nov 29, 2012 at 7:49
du -shc */ .??*/
(The ?? is to exclude . and ..)
Nov 30, 2012 at 10:17
.
directory. It also gives you the choice to see the sum total or not.
Dec 3, 2012 at 19:38
This one should do the job efficiently :
du -hc --max-depth=1
One big difference I think of is that, when encountering hardlinked files, they will be counted only once. In a find loop, they will be counted once per base directory. [Is it correct english?]
I'm using this one,
ls | xargs du -sh
basically there are many ways to skin a cat :)
You can also do this:
du -ah .
What it does is to take the subdirectories of the current directory, find its individual's size and in the end, it prints the total size.