A Handy Linux Script

Submitted by nickw on Mon, 2006-10-16 08:23. :: |

So back at Gottathink I ran into a slight problem with a customer taking up 11G of our precious 30G spindle on one of the VPS accounts. My boss was (of course) freaking out and wanting to know who it was.

Well unfortunately Gottathink hadn't implemented quotas on any boxes up until that point (I didn't set them up so don't glare at me like that) so I had to whip up something that would tell me the offender quickly.

The following script came to me:

for i in *; do if [ -d $i ]; then du -hs $i; fi; done

What this does is simply find out the size of every directory that exists in the current directory.

It would be really easy to make this recursive so you could pinpoint the problem if need be.

If you need to limit the number of returned records, simply pipe the output through sed or if you're really lazy, grep.