5

I'm trying to use du to investigate disk usage in a directory like so:

du -hd1 | sort -rh

This gives me a list that starts as follows

61G     .
7.9G    ./A
5.1G    ./B
2.7G    ./.C
1.6G    ./.D
1.2G    ./.E
1.2G    ./F
850M    ./.G
724M    ./H
666M    ./I
281M    ./J
249M    ./.K
150M    ./.L

The rest of the list sums up to less than 1GB and there are no large files directly contained in that directory:

ls -Slh
total 1.8M
...

What is the source of the discrepancy between the total 61GB and the sum of less than 25GB of the directory sums?

3 Answers3

8

The calls above miss large hidden files. Here is the result with du -a

du -ahd1 .  | sort -rh | head
61G     .
38G     ./.xsession-errors
7.9G    ./A
5.1G    ./B
...
0

As I understand it, du calculates the whole subtree usage, and option -d1 only prints data up to the first hierarchie level. Your ls calculates only the first level.

Janis
  • 14,222
-1

if you just want one total;

# du -ms
Archemar
  • 31,554