Note: You are viewing an old version of this page. View the current version.

Compute a sorted disk usage analysis using du, without including filesystem mountpoints

case $(uname -s) in
Linux)
  duso() {
    sudo sh -e <<"EOF"
    mnt="$(stat -c %m .)"
    LANG=C ls -1a | grep -Gv '^\.$\|^\.\.$' | while read dent
    do
      [ "$(stat -c %m "${dent}")" = "${mnt}" ] && printf "%s\0" "${dent}"
    done | xargs -0 du -sx | sort -bn
EOF
  }
  ;;
FreeBSD)
  duso() {
    sudo sh -e <<"EOF"
    mnt="$(stat -f %d .)"
    LANG=C ls -1a | grep -Gv '^\.$\|^\.\.$' | while read dent
    do
      [ "$(stat -f %d "${dent}")" = "${mnt}" ] && printf "%s\0" "${dent}"
    done | xargs -0 du -sx | sort -bn
EOF
  }
  ;;
*) echo "Unknown platform $(uname -s)" ;;
esac