du
does a depth-first traversal of the given tree. By default, it shows the usage of every directory tree, showing the inclusive disk usage of each:
$ du ~
4 /home/bob/Videos
40 /home/bob/.cache/abrt
43284 /home/bob/.cache/mozilla/firefox
43288 /home/bob/.cache/mozilla
12 /home/bob/.cache/imsettings
48340 /home/bob/.cache
4 /home/bob/Documents
48348 /home/bob
If given the -a
option, it will additionally show the size of every file.
With the -s
option, it will show just the total size of each argument file or directory tree.
$ du -s ~
48348 /home/bob
$ du -s ~/*
4 /home/bob/Videos
4 /home/bob/Documents
So, when you ran
$ du -b ~ | wc -l
15041
$ du -b ~ | sort -n | head -n 15040 | cut -f 1 | \
perl -ne 'BEGIN{$i=0;$i+=$_;END{print $i.qq|\n|;}'
12735983847
you were summing up the size of everything under your home directory - multiple times, unfortunately, because the size reported on each line is inclusive of all subdirectories - but because you omitted the final line of du's output, which would be the line for /home/steven
, du
didn't count the size of any of the regular files in the top level of your home directory. So the sum didn't include your very large .xsession-errors
file.
And when you ran
du -sb ~ returns 91296460205, but the sum of du -sb ~/* is only 1690166532
your du -sb ~/*
output didn't include any files or directories in your home directory that begin with .
.
Both du ~ | tail -1
and du -s ~
should do a reasonable job of showing your home directory's disk usage (not including deleted-but-open files, of course), but if you want to sum up all the file sizes without relying on du
, you can do something like this (assuming a modern find
that supports the printf %s
format to show the size in bytes):
find ~ -type f -printf '%s\n' | perl -ne 'BEGIN{$i=0;$i+=$_;END{print $i.qq|\n|;}'
Also checkout ncdu:
http://dev.yorhel.nl/ncdu
Its page also lists other "similar projects":
gt5 - Quite similar to ncdu, but a different approach.
tdu - Another small ncurses-based disk usage visualization utility.
TreeSize - GTK, using a treeview.
Baobab - GTK, using pie-charts, a treeview and a treemap. Comes with GNOME.
GdMap - GTK, with a treemap display.
Filelight - KDE, using pie-charts.
KDirStat - KDE, with a treemap display.
QDiskUsage - Qt, using pie-charts.
xdiskusage - FLTK, with a treemap display.
fsv - 3D visualization.
Philesight - Web-based clone of Filelight.
Best Answer
Only for tree 1.6 and above
You might want to look at:
So you should use: