Finding the Size of a Directory Using du


Here is an easy way to find out the the number of Kilobytes your directories are taking up. For example, when doing backups, sometimes I will notice a particular directory has ballooned in size for no apparent reason. Often this is because I copied a file someplace and forgot to clean up after myself.
The du command is really good for looking up this kind of information. It recursively searches directories and returns the number of blocks or bytes each directory and all of its subdirectories are using. The following command will list all the subdirectory sizes of the current directory in kilobytes. The command is then piped through sort to sort the directory list by size in K. Below are several examples of how to use the command on several different platforms.

Mac OS X Example

du -k -d 2 | sort -n
~/Pictures $ dirsize
0       ./Palm Photos
204     ./Temp
4344    ./Backgrounds
4556    .
  

Cygwin Example

du --max-depth=1 -k | sort -n
  
www.comhttp.blogspot.in. Powered by Blogger.