Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I often find myself having to clean up some directories because they are too full. Let's take /var as an example, as it is a common one, for obvious reasons.

In order to see which sub-directories takes a lot of space, I use du -sh /var/*. Unfortunately, I have some huge data in sub-directories of /var, which happen to be hosted on other partitions than /var (e.g. /var/chroot) and greatly slow the process for nothing.

Now du has a -x flag which excludes other mountpoints. It works fine when doing a du -shx /var but not with du -shx /var/* since * is expanded by the shell so /var/chroot is explicitely sent to du.

Another option I was proposed was to use find /var -xdev -mindepth 1 -maxdepth 1 -exec du -sh {} \+ but again, even though find does not follow other mountpoints, it still prints them and passes them to du, hence failing again to achieve my goal.

Before I end up writing a horrible bash function (or a perl/python program) that parses df or mount in a loop, does anyone know of a clean way to achieve what I'm trying to do?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

it looks like what you need is this:

du -hx --max-depth 1 /var
share|improve this answer
    
Ok, you posted your answer right as I was answering myself, so you get the vote :-) Thank you. –  ℝaphink Oct 6 '10 at 16:02
    
You're welcome :) –  Hubert Kario Oct 6 '10 at 16:12

I got the answer from a colleague:

du -hx --max-depth=1 /var

does the trick.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.