Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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


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.