Finding Directory Sizes in Linux

From KallestadWiki

Jump to: navigation, search

Here's a quick script that will print out directory sizes (in megabytes): You can put this in /usr/sbin and run it as root. You can also run it as an unpriveleged user, but you may not get accurate information if you do not have access to all subdirectories.

#!/bin/bash
du -sm $(find $1 -maxdepth 1 -xdev -type d) | sort -g

To find the size of all subdirectories, use this one:

#!/bin/bash
find $1 -type d |xargs du -sm | sort -g

If you just want to run either of these from the command line, replace $1 with "./" - i.e.

find ./ -type d |xargs du -sm | sort -g
Personal tools