brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: du -x stays on one filesystem so a mounted disk does not skew the total

Disk
~/tips/tip-disk-du-x-one-filesystem

sudo du -xh -d1 / | sort -h

Totals folder sizes without crossing into other mounted filesystems.

Running du on / to find out what fills the root disk is a classic. The result is confusing when other disks are mounted below it: it counts everything that lives under those mount points too.

The option -x (--one-file-system) skips directories on other filesystems:

sudo du -xh -d1 / | sort -h

Now the numbers describe the filesystem you asked about. On a server where /mnt holds several big disks, they no longer swamp the list, and -d1 keeps the output to one level of directories. I add sort -h so the largest folders come last, where the eye lands.

Because it skips directories on other filesystems, it also keeps the command from walking into a mounted network share, which can take a very long time.

Compare it with a plain run once. If a directory shrinks a lot with -x, something is mounted there. That is a quick way to see the layout of mounts you forgot about.

The caveat: whatever is mounted below the path is left out of the totals. That is the point, but it also means the number can be smaller than what the folder seems to hold. If you want the size of a mounted disk, run du on its mount point separately. And du does not follow symbolic links by default, but with -L it does, so a link to another disk is counted when you add that flag.

Further reading: du(1) manual page

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link