Linux – du -x still examines mounted filesystems when using wildcards

dufilesystemslinuxmount

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.

Best Answer

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
Related Question