28

If the wording of the question is wrong, please let me know. It might explain why I can’t find an answer.

I want to find the usage on my main disk using a command like:

du -sh /*

The problem is that I have a number of mount points at the root level, and I would like du to skip these.

I thought the -x option was supposed to do this, but either I misunderstand what it does or I’m using it the wrong way.

How can I apply du to only the root disk without traversing the additional mounts?

Thanks

6
  • In other words, are you looking for summary usage of /bin, /etc, and other folders under /, while excluding /run, /proc/, /sys, and so on? Commented May 17, 2016 at 22:44
  • I also have additional drives mounted at /data and /backup and so on, but that’s basically correct.
    – Manngo
    Commented May 17, 2016 at 22:47
  • 1
    I think you are using du properly, the problem is that /* is expanding to include every mount point under /, then du iterates over each one, which defeats the -x usage. The only way to solve this might be with a creative script. Commented May 17, 2016 at 22:54
  • @jamieguinan What would be wrong with replacing /* with /? Why would that not fix it and instead require a creative script? Commented Mar 29, 2018 at 2:20
  • @DuncanXSimpson / would only show the sum total of /. He wanted to see the subtotals for non-mounted folders. Commented Mar 29, 2018 at 14:55

2 Answers 2

71

du -x will not traverse any mount points it encounters. But if it is told to start at a mount point then it will do as requested.

2
  • 2
    To build on this, if you have a volume mounted in the root directory, du -shx /* will scan the volume since you are starting on the mounted volume.
    – Dash
    Commented Jan 22, 2021 at 0:20
  • 1
    AKA, do not put the star: du -hx /
    – Compholio
    Commented Oct 27, 2023 at 15:21
18

This is hacky, but it seems to do what you want, from the shell,

for d in /*; do egrep " ${d} " /proc/mounts > /dev/null || du -sh ${d}; done

Add a sudo in front of the du if needed.

3
  • 3
    Sorry it’s taken me so long to accept this. Your comment above, I think, explains why the -x isn’t working, and your answer is a solution. In my own usage, I have modified it as follows: for i in /*; do if ! mountpoint -q "$i"; then du -sh $i; fi; done;. Thanks
    – Manngo
    Commented Mar 15, 2017 at 0:07
  • 3
    You can avoid the for loop: du -d1 -x means starting in the current directory, go down to a depth of 1 (so, single level of subdirectories), and also skip directories on different file systems. My rootfs is an ssd, but also have a zfs raid mounted, and I wanted to do a quick check of what's taking up space on the ssd without wasting time on the hard drives; this works.
    – ecloud
    Commented Jan 15, 2021 at 6:49
  • but -s conficts with -d1 what was the original question
    – Hrobky
    Commented Jul 9, 2021 at 16:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.