How to find biggest mailboxes in Linux

Applicable to Ubuntu and post-CentOS operating systems, this method displays all Maildir directories in all /home/ directories together with their size:

find /home/ -name Maildir -type d -exec du -hs --summarize --block-size=1M {} \; | awk '{if ($1 > 2000) print $1 " " $2}'

It has 3 sections:

  1. Find: well, it finds stuff 🙂 -name Maildir limits the results to the interesting ones; -type d limits to directories
  2. Exec du: executes du on each entry to get the sizes; -hs to make it human readable and summarized (a number); –block-size to use a locked size for all, easier to compare
  3. Awk: filters the results, basically if first parameter $1 (which is what du says about that size) is bigger than the supplied number (2000 in this case) then it prints parameter $1 (the size), followed by a space, followed by parameter $2, which is the directory full path.

A usual output looks like this:

2386 /home/group-name-1/homes/user.name/Maildir
6186 /home/group-name-1/homes/user.name/Maildir
2098 /home/group-name-1/homes/user.name/Maildir
9687 /home/group-name-1/homes/user.name/Maildir
2308 /home/group-name-1/homes/user.name/Maildir

On the left is size in megabytes, on the right is the full path.

If you are looking for multi-gigabytes mailboxes, you could change –block-size to 1G and ($1 > 2), that would display all the mailboxes bigger than 2 gigabytes; or if you look for mailboxes bigger than 100 megabytes, that would be –block-size=1M and ($1 > 100), like this:

find /home/ -name Maildir -type d -exec du -hs --summarize --block-size=1M {} \; | awk '{if ($1 > 2000) print $1 " " $2}'

Sometimes the output can take a long time (minutes) especially on olders systems; sometimes command can exit without results, which means the size set for awk is too big, in this case removing the awk part would display all the mailboxes and could help making a better decision about what size to use for filtering.

Leave a Reply