20

I need to find out what's contributing to the disk usage on a specific filesystem (/dev/sda2):

$ df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              96G   82G  9.9G  90% /

I can't just do du -csh / because I have many other filesystems mounted underneath /, some of which are huge and slow:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              96G   82G  9.9G  90% /
/dev/sdb1             5.2T  3.7T  1.3T  76% /disk3
/dev/sda1              99M   18M   76M  20% /boot
tmpfs                  16G  4.0K   16G   1% /dev/shm
nfshome.XXX.net:/home/userA
                      5.3T  1.6T  3.5T  32% /home/userA
nfshome.XXX.net:/home/userB
                      5.3T  1.6T  3.5T  32% /home/userB

How can I retrieve disk usage only on /dev/sda2?

None of these work:

  • Attempt 1:

    $ du -csh /dev/sda2
    0       /dev/sda2
    0       total
    
  • Attempt 2:

    $ cd /dev/sda2/
    cd: not a directory: /dev/sda2/
    
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294

3 Answers3

29

Use the -x (single file system) option:

du -cshx /

This instructs du to only consider directories of / which are on the same file system.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Thanks Stephen. Not sure this works the way I understand it does (see [this followup](http://unix.stackexchange.com/questions/358323/du-results-on-filesystem-inconsistent-with-df)) – Amelio Vazquez-Reina Apr 11 '17 at 13:45
  • Note that the magic here is the `-x` option. The other options here, mirroring the OP approach, report in human-readable numbers, and summarize the results, including a grand total. So for example, `du -x /` would give a full description of all files on the root file system. – nealmcb Jul 31 '21 at 17:03
  • The problème is that one would normally do `du -x /*` - to see what directory is using the most of the space of the root partition. How to exclude from this result the directories that are on a different filesystem? – Andrei Boyanov Dec 05 '22 at 06:55
  • @Andrei if you’re using GNU `du`, `du -x --max-depth=1 /`. – Stephen Kitt Dec 05 '22 at 08:49
1

There are two options to solving your problem:

Using the option --exclude which makes du ignore the given path.

du --human-readable --exclude=/home

Using the option --one-file-system would tell du to not go into a different file system.

du --human-readable --one-file-system /
Willian Paixao
  • 2,691
  • 3
  • 18
  • 33
  • I have home on a different partition but when I use `du -hd1x \` the home directory is included. I use debian stretch. What do I misunderstand in "one file system"? – user855443 Nov 26 '18 at 22:56
  • To find directories containing a large size, I would recommend adding `--max-depth=1`: `du --human-readable --one-file-system --max-depth=1` – koppor Sep 24 '21 at 07:50
0

On some Linux distro you could take advantage of ncdu.

To check your HOME folder:

$ ncdu ~
malat
  • 2,708
  • 4
  • 27
  • 47