Skip to main content
added 18 characters in body
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

Alternatively, you could use GNU find to find the files and useprint their disk usage, calling the GNU mountpoint command to determineknow which directories to prune (which are bind-mounts and have it report the disk usage by itself). Then use awk to do the sums (counting hardlinks only once like du does):

find . -xdev ! -name . -type d -exec mountpoint -q {} \; -prune -o \
       -printf '%i %b\n' |
  awk '!seen[$1]++ {s+=$2}
       END{printf "%.17g\n", s * 512}' |
  numfmt --to=iec

That's quite inefficient though in that it needs to run the mountpoint command for each directory (note that it's also possible to bind-mount non-directory files, we're assuming it's not done to avoid running mountpoint on each file).

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

Alternatively, you could use GNU find and use the GNU mountpoint to determine which directories are bind-mounts and have it report the disk usage by itself. Then use awk to do the sums (counting hardlinks only once like du does):

find . -xdev ! -name . -type d -exec mountpoint -q {} \; -prune -o \
       -printf '%i %b\n' |
  awk '!seen[$1]++ {s+=$2}
       END{printf "%.17g\n", s * 512}' |
  numfmt --to=iec

That's quite inefficient though in that it needs to run the mountpoint command for each directory (note that it's also possible to bind-mount non-directory files, we're assuming it's not done to avoid running mountpoint on each file).

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

Alternatively, you could use GNU find to find the files and print their disk usage, calling the mountpoint command to know which directories to prune (which are bind-mounts). Then use awk to do the sums (counting hardlinks only once like du does):

find . -xdev ! -name . -type d -exec mountpoint -q {} \; -prune -o \
       -printf '%i %b\n' |
  awk '!seen[$1]++ {s+=$2}
       END{printf "%.17g\n", s * 512}' |
  numfmt --to=iec

That's quite inefficient though in that it needs to run the mountpoint command for each directory (note that it's also possible to bind-mount non-directory files, we're assuming it's not done to avoid running mountpoint on each file).

added 681 characters in body
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

Alternatively, you could use GNU find and use the GNU mountpoint to determine which directories are bind-mounts and have it report the disk usage by itself. Then use awk to do the sums (counting hardlinks only once like du does):

find . -xdev ! -name . -type d -exec mountpoint -q {} \; -prune -o \
       -printf '%i %b\n' |
  awk '!seen[$1]++ {s+=$2}
       END{printf "%.17g\n", s * 512}' |
  numfmt --to=iec

That's quite inefficient though in that it needs to run the mountpoint command for each directory (note that it's also possible to bind-mount non-directory files, we're assuming it's not done to avoid running mountpoint on each file).

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point

Alternatively, you could use GNU find and use the GNU mountpoint to determine which directories are bind-mounts and have it report the disk usage by itself. Then use awk to do the sums (counting hardlinks only once like du does):

find . -xdev ! -name . -type d -exec mountpoint -q {} \; -prune -o \
       -printf '%i %b\n' |
  awk '!seen[$1]++ {s+=$2}
       END{printf "%.17g\n", s * 512}' |
  numfmt --to=iec

That's quite inefficient though in that it needs to run the mountpoint command for each directory (note that it's also possible to bind-mount non-directory files, we're assuming it's not done to avoid running mountpoint on each file).

Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

du -x (at least GNU and busybox du) is fooled by Linux bind-mounts because files have the same device-id, so you'd need to prune the mount-points by hand. With GNU du:

du -xhs --exclude=./bind/mount/point