Sunday, February 04, 2007

Determine the Directory Size Recursively

Sometimes you want to ascertain the space hogs on your system. You might have noticed that a certain top level directory is larger than usual, but you are unsure what subdirectory or subdirectories are the culprits.

Here's an example of what can be done:

#cd /huge_directory
#du -k . (current directory size given in kilobytes)

To find the sizes recursively (subdirectories):

#cd /huge_directory
#for size in 'ls'
du -k $size
echo $size done


devendra.vyavahare[at]gmail[dot]com said...

#find /huge_directory -type d -size +100 -print

is not giving correct results on my machine. I think size for the directory is computed recursively when we check for -size +100 in find.

Correct me I am wrong.
~ Devendra...aja

devendra.vyavahare[at]gmail[dot]com said...

there was typo in my earlier comment
please replace
"is computed recursively"
as "is NOT computed recursively"

esofthub said...

devendra, when I wrote that post awhile ago, I was having problems with other folks putting large files in my root partition.

The (the find) second part was an afterthought (posted a few days later). Apparently I was thinking about files. It shouldn't have been posted. At any rate, I appreciate the correction. (Nowadays I check everything on my UNIX box before posting.) This is a good example for doing just that. Thanks.