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?
it looks like what you need is this:
I got the answer from a colleague:
du -hx --max-depth=1 /var
does the trick.