7

If I try

du -s -h -x /*

it will try to examine all filesystems (real and pseudo) mounted directly under /, e.g. /dev, /proc, /sys, /run, and /home (/home is on an extra partition).

I think it comes from the shell expansion of *, giving du a parameter list that explicitly includes these mount points.

Is there a way to make du not examine mounted filesystems, even when the mount points are contained in the parameter list ?

I really don't want to type all subdirs of / just to avoid them being in the parameter list.

Markus N.
  • 585

3 Answers3

4

You can still filter that using mountpoint (if available on your system):

for a in /*; do mountpoint -q -- "$a" || du -s -h -x "$a"; done

If mountpoint is not available but stat is (while stat is still not POSIX, it may be more common), you will have to compare the stat output manually:

rootdevice="$(stat -c %D /)"
for a in /*; do [ "$rootdevice" = "$(stat -c %D -- "$a")" ] && du -s -h -x "$a"; done
BatchyX
  • 2,486
  • 17
  • 12
2

Doesn't use * in your du command. Use something akin to:

du -hx --max-depth=1| sort -h

or

du -hx / --max-depth=1| sort -h
Worthwelle
  • 4,816
2

I guess you're right. You are actually saying du /dev, du /sys, du /usr, du /home so the "-x" option is meaningless.

Why don't you loop over it? E.g. find / -maxdepth 1 | egrep -v home|media will list all dirs except home and media. Then you can pipe the output to a while loop to du it.

find / -maxdepth 1 | egrep -v home|media | while read f; do
  du -s -h -x "$f"; 
done